You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes you want to test if cancellation of requests is working. In that case, the mocked request should not finished directly and you need an delay. This can be added easily:
136
+
137
+
```swift
138
+
let exampleURL =URL(string: "https://www.wetransfer.com/api/endpoint")!
139
+
140
+
var mock =Mock(url: exampleURL, contentType: .json, statusCode: 200, data: [
141
+
.head: MockedData.headResponse.data,
142
+
.get: MockedData.exampleJSON.data
143
+
])
144
+
mock.delay= DispatchTimeInterval.seconds(5)
145
+
mock.register()
146
+
```
147
+
148
+
##### Redirect responses
149
+
Sometimes you want to mock short URLs or other redirect URLs. This is possible by saving the response and mock the redirect location, which can be found inside the response:
150
+
151
+
```
152
+
Date: Tue, 10 Oct 2017 07:28:33 GMT
153
+
Location: https://wetransfer.com/redirect
154
+
```
155
+
156
+
By creating a mock for the short URL and the redirect URL, you can mock redirect and test this behaviour:
157
+
158
+
```swift
159
+
let urlWhichRedirects: URL =URL(string: "https://we.tl/redirect")!
As the Mocker catches all URLs when registered, you might end up with a `fatalError` thrown in cases you don't need a mocked request. In that case you can ignore the URL:
166
+
167
+
```swift
168
+
let ignoredURL =URL(string: "www.wetransfer.com")!
0 commit comments