-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
607a84e
commit 1296413
Showing
13 changed files
with
105 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
--- | ||
title: "Inspection fundamentals" | ||
position: 0 | ||
description: |- | ||
`fetch-mock`'s inspection methods allow information about how `fetch` was called to be retrieved after your application code has run. Most inspection methods take two arguments — `filter` and `options` — which allow individual, or groups of, `fetch` calls to be extracted and examined. | ||
parameters: | ||
- name: filter | ||
content: |- | ||
Filter calls to `fetch` using one of the following criteria: | ||
options: | ||
- types: | ||
- undefined | ||
content: |- | ||
Retrieve all calls made to `fetch` | ||
- types: | ||
- true | ||
content: |- | ||
Retrieve all calls to `fetch` matched by some route defined by `fetch-mock`. `fetchMock.MATCHED` is an alias for `true` and may be used to make tests more readable | ||
examples: | ||
- |- | ||
const {MATCHED, fetchMock} = require('fetch-mock'); | ||
... | ||
fetchMock.calls(MATCHED) | ||
- types: | ||
- false | ||
content: |- | ||
Retrieves all calls to `fetch` not matched by a route (i.e. those handled by `catch()`, `spy()` or the `fallbackToNetwork` option). `fetchMock.UNMATCHED` is an alias for `false` and may be used to make tests more readable | ||
examples: | ||
- |- | ||
const {UNMATCHED, fetchMock} = require('fetch-mock'); | ||
... | ||
fetchMock.calls(UNMATCHED) | ||
- name: routeIdentifier | ||
types: | ||
- String|RegExp|function | ||
content: |- | ||
All routes have an identifier: | ||
- If it's a [named route](#api-mockingmock_options), the identifier is the route's `name` | ||
- If the route is unnamed, the identifier is the value of the `matcher` argument that was passed in to `.mock()` | ||
All calls that were handled by the route with the given identifier will be retrieved | ||
- name: matcher | ||
types: | ||
- String|RegExp|function | ||
content: |- | ||
Any matcher compatible with the [mocking api](#api-mockingmock_matcher) can be passed in to filter the calls arbitrarily. The matcher will be executed using exactly the same rules as the mocking api | ||
- name: options | ||
types: | ||
- Object | ||
- String | ||
content: |- | ||
Either an object compatible with the [mocking api](#api-mockingmock_options) or a string specifying a http method to filter by. This will be used to filter the list of calls further | ||
content_markdown: |- | ||
The filtering API is powerful, but potentially confusing. If in doubt, [add a `name` to your route](#api-mockingmock_options), and pass that name in to retrieve exactly the calls you want. | ||
#### A note on Regular Expression and Function matchers | ||
To retrieve calls handled by a route with a `RegExp` or `function` matcher, use a reference to the exact `RegExp`|`function` you used in your mock, e.g. | ||
```javascript | ||
const matcherRX = /user\/biff/ | ||
fm.mock(matcherRX, 200) | ||
... | ||
fm.called(matcherRX) | ||
``` | ||
not | ||
```javascript | ||
fm.mock(/user\/biff/, 200) | ||
... | ||
fm.called(/user\/biff/) | ||
``` | ||
The second example _will_ retrieve the expected calls in simple test scenarios because if no routes match using the identifier the `RegExp` will be executed as a `RegExp` matcher. But in more complex scenarios where e.g. there are several routes handling similar paths, it might retrieve calls that were actually handled by different, similar route e.g. | ||
```javascript | ||
const matcherRX = /user\/biff/ | ||
fm | ||
.mock('end:user/biff') | ||
.mock(matcherRX, 200) | ||
... | ||
// this will retrieve calls handled by either route | ||
fm.called(/user\/biff/) | ||
// this will retrieve only calls handeld by the second route | ||
fm.called(/user\/biff/) | ||
``` | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters