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
Creates a route that only responds to a single request using a particular http method
67
67
68
+
## modifyRoute(routeName, options)
69
+
70
+
Modifies a route's behaviour, overwriting any options (including matcher and response) passed into the named route when first created. Useful when writing tests for special cases that require different behaviour to that required by the majority of your tests. To remove an option, pass in null in the options e.g. `.modifyRoute('my-name', {headers: null})`.
71
+
72
+
## removeRoute(routeName)
73
+
74
+
Removes a route. Useful when writing tests for special cases that do not require a route that's required by the majority of your tests.
75
+
68
76
## .addMatcher(options)
69
77
70
78
Allows adding your own, reusable custom matchers to fetch-mock, for example a matcher for interacting with GraphQL queries, or an `isAuthorized` matcher that encapsulates the exact authorization conditions for the API you are mocking, and only requires a `true` or `false` to be input
Copy file name to clipboardexpand all lines: docs/docs/Usage/upgrade-guide.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -43,7 +43,7 @@ The same is true for `postOnce()`, `deleteOnce()` etc.
43
43
44
44
### Options removed
45
45
46
-
-`overwriteRoutes` - this reflects that multiple routes using the same underlying matcher but different options no longer throw an error.
46
+
-`overwriteRoutes` - this reflects that multiple routes using the same underlying matcher but different options no longer throw an error. If you still need to overwrite route behaviour (equivalent to `overwriteRoutes: true`) use [`modifyRoute()` or `removeRoute()`](/fetch-mock/docs/API/more-routing-methods#)
47
47
-`warnOnFallback` - given the improved state of node.js debugging tools compared to when fetch-mock was first written, this debugging utilty has been removed.
48
48
-`sendAsJson` - fetch-mock@12 implements streams more robustly than previous options, so the user no longer needs to flag when an object response should be converted to JSON.
49
49
-`fallbackToNetwork` - The [`spyGlobal()` method](/fetch-mock/docs/API/mocking-and-spying#spyglobal) should now be used.
Copy file name to clipboardexpand all lines: packages/codemods/README.md
+2-1
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,8 @@ For everyt variable containing an instance of fetch-mock imported using `require
27
27
- Rewrite `.lastUrl()`, `.lastOptions()` and `lastResponse()` to their equivalents in fetch-mock@12
28
28
- Adds an informative error whenever `.lastCall()` or `.calls()` are used with advice on how to manually correct these
29
29
- Converts `.getOnce()`, `.getAnyOnce()`, `.postOnce()` etc... - which have been removed - to calls to the underlying `.get()` method with additional options passed in.
30
-
- Removes uses of the deprecated options `overwriteRoutes`, `warnOnFallback`, `sendAsJson`
30
+
- Removes uses of the deprecated options `warnOnFallback` and `sendAsJson`
31
+
- Removes uses of the deprecated `overwriteRoutes` option, and adds an informative error with details of how to replace with the `modifyRoute()` method
31
32
- Removes uses of the deprecated `fallbackToNetwork` option, and adds an informative error with details of how to replace with the `spyGlobal()` method
0 commit comments