@@ -74,7 +74,7 @@ It's recommend to create a class with all your mocked data accessible. An exampl
74
74
75
75
``` swift
76
76
public final class MockedData {
77
- public static let botAvatarImageResponseHead: Data = Bundle (for : MockedData.self ).url (forResource : " Resources/Responses/bot-avatar-image-head" , withExtension : " data" )! . data
77
+ public static let botAvatarImageResponseHead: Data = try ! Data ( contentsOf : Bundle (for : MockedData.self ).url (forResource : " Resources/Responses/bot-avatar-image-head" , withExtension : " data" )! )
78
78
public static let botAvatarImageFileUrl: URL = Bundle (for : MockedData.self ).url (forResource : " wetransfer_bot_avater" , withExtension : " png" )!
79
79
public static let exampleJSON: URL = Bundle (for : MockedData.self ).url (forResource : " Resources/JSON Files/example" , withExtension : " json" )!
80
80
}
@@ -85,7 +85,7 @@ public final class MockedData {
85
85
let originalURL = URL (string : " https://www.wetransfer.com/example.json" )!
86
86
87
87
let mock = Mock (url : originalURL, dataType : .json , statusCode : 200 , data : [
88
- .get : MockedData.exampleJSON . data // Data containing the JSON response
88
+ .get : try ! Data ( contentsOf : MockedData.exampleJSON ) // Data containing the JSON response
89
89
])
90
90
mock.register ()
91
91
@@ -108,7 +108,7 @@ Some URLs like authentication URLs contain timestamps or UUIDs in the query. To
108
108
let originalURL = URL (string : " https://www.example.com/api/authentication?oauth_timestamp=151817037" )!
109
109
110
110
let mock = Mock (url : originalURL, ignoreQuery : true , dataType : .json , statusCode : 200 , data : [
111
- .get : MockedData.exampleJSON . data // Data containing the JSON response
111
+ .get : try ! Data ( contentsOf : MockedData.exampleJSON ) // Data containing the JSON response
112
112
])
113
113
mock.register ()
114
114
@@ -128,7 +128,7 @@ URLSession.shared.dataTask(with: originalURL) { (data, response, error) in
128
128
let imageURL = URL (string : " https://www.wetransfer.com/sample-image.png" )!
129
129
130
130
Mock (fileExtensions : " png" , dataType : .imagePNG , statusCode : 200 , data : [
131
- .get : MockedData.botAvatarImageFileUrl . data
131
+ .get : try ! Data ( contentsOf : MockedData.botAvatarImageFileUrl )
132
132
]).register ()
133
133
134
134
URLSession.shared .dataTask (with : imageURL) { (data, response, error) in
@@ -141,8 +141,8 @@ URLSession.shared.dataTask(with: imageURL) { (data, response, error) in
141
141
let exampleURL = URL (string : " https://www.wetransfer.com/api/endpoint" )!
142
142
143
143
Mock (url : exampleURL, dataType : .json , statusCode : 200 , data : [
144
- .head : MockedData.headResponse . data ,
145
- .get : MockedData.exampleJSON . data
144
+ .head : try ! Data ( contentsOf : MockedData.headResponse ) ,
145
+ .get : try ! Data ( contentsOf : MockedData.exampleJSON )
146
146
]).register ()
147
147
148
148
URLSession.shared .dataTask (with : exampleURL) { (data, response, error) in
@@ -157,8 +157,8 @@ Sometimes you want to test if cancellation of requests is working. In that case,
157
157
let exampleURL = URL (string : " https://www.wetransfer.com/api/endpoint" )!
158
158
159
159
var mock = Mock (url : exampleURL, dataType : .json , statusCode : 200 , data : [
160
- .head : MockedData.headResponse . data ,
161
- .get : MockedData.exampleJSON . data
160
+ .head : try ! Data ( contentsOf : MockedData.headResponse ) ,
161
+ .get : try ! Data ( contentsOf : MockedData.exampleJSON )
162
162
])
163
163
mock.delay = DispatchTimeInterval.seconds (5 )
164
164
mock.register ()
@@ -176,8 +176,8 @@ By creating a mock for the short URL and the redirect URL, you can mock redirect
176
176
177
177
``` swift
178
178
let urlWhichRedirects: URL = URL (string : " https://we.tl/redirect" )!
179
- Mock (url : urlWhichRedirects, dataType : .html , statusCode : 200 , data : [.get : MockedData.redirectGET . data ]).register ()
180
- Mock (url : URL (string : " https://wetransfer.com/redirect" )! , dataType : .json , statusCode : 200 , data : [.get : MockedData.exampleJSON . data ]).register ()
179
+ Mock (url : urlWhichRedirects, dataType : .html , statusCode : 200 , data : [.get : try ! Data ( contentsOf : MockedData.redirectGET ) ]).register ()
180
+ Mock (url : URL (string : " https://wetransfer.com/redirect" )! , dataType : .json , statusCode : 200 , data : [.get : try ! Data ( contentsOf : MockedData.exampleJSON ) ]).register ()
181
181
```
182
182
183
183
##### Ignoring URLs
0 commit comments