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
feat: Global mode to choose only to mock registered routes (#84)
* feat: Added a global mode selection to be able to only mock registered routes, and let every other url to be processed as if the Mocker is not present.
* refactor: Reorganizing subtype position and fixing documentation following @AvdLee advices.
* fix: Added unit tests to Mocker mode
* fix: Fixing SwiftLint rule `switch_case_on_newline`
* fix: Updated documentation chapter on Ignoring URLs to add the new mode
* fix: typo
Copy file name to clipboardexpand all lines: README.md
+13-1
Original file line number
Diff line number
Diff line change
@@ -181,13 +181,25 @@ Mock(url: URL(string: "https://wetransfer.com/redirect")!, dataType: .json, stat
181
181
```
182
182
183
183
##### Ignoring URLs
184
-
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:
184
+
As the Mocker catches all URLs by default 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:
185
185
186
186
```swift
187
187
let ignoredURL =URL(string: "www.wetransfer.com")!
188
188
Mocker.ignore(ignoredURL)
189
189
```
190
190
191
+
However if you need the Mocker to catch only mocked URLs and ignore every other URL, you can set the `mode` attribute to `.optin`.
192
+
193
+
```swift
194
+
Mocker.mode= .optin
195
+
```
196
+
197
+
If you want to set the original mode back, you have just to set it to `.optout`.
198
+
199
+
```swift
200
+
Mocker.mode= .optout
201
+
```
202
+
191
203
##### Mock errors
192
204
193
205
You can request a `Mock` to return an error, allowing testing of error handling.
0 commit comments