fetchMock = function () { [native code] }
n/a
reset = function () { [native code] }
...
The commonest use case is `fetchMock.mock(matcher, response)`, where `matcher` is a string or regex to match and `response` is a
statusCode, string or object literal. You can also use `fetchMock.once(url ...)` to limit to a single call or `fetchMock.get()`, `
fetchMock.post()` etc. to limit to a method. All these methods are chainable so you can easily define several mocks in a single
test.
## Analysing calls to your mock
`fetchMock.called(matcher)` reports if any calls matched your mock (or leave `matcher` out if you just want to check `fetch` was
called at all). `fetchMock.lastCall()`, `fetchMock.lastUrl()` or `fetchMock.lastOptions()` give you access to the parameters last
passed in to `fetch`. `fetchMock.done()` will tell you if `fetch` was called the expected number of times.
## Tearing down your mock
`fetchMock.reset()` resets the call history. `fetchMock.restore()` will also restore `
fetch()` to its native implementation
## Example
Example with node: suppose we have a file `make-request.js` with a function that calls `fetch`:
```js
module.exports = function makeRequest() {
return fetch("http://httpbin.org/get").then(function(response) {
...
restore = function () { [native code] }
...
#### `restore()`
Chainable method that restores `fetch()` to its unstubbed state and clears all data recorded for its calls.
#### `reset()`
Chainable method that clears all data recorded for `fetch()`'s calls
*Note that `restore()` and `reset()` are both bound to fetchMock, and can be used directly as callbacks e.g. `afterEach(fetchMock
.restore)` will work just fine. There is no need for `afterEach(function () {fetchMock.restore
()})`*
## Analysing how `fetch()` has been called
**For the methods below `matcherName`, if given, should be either the name of a route (see advanced usage below) or equal to `matcher
.toString()` for any unnamed route. You _can_ pass in the original regex or function used as a matcher, but they will be converted
to strings and used to look up values in fetch-mock's internal maps of calls, rather than used as regexes or functions**
#### `called(matcherName)`
Returns a Boolean indicating whether fetch was called and a route was matched. If `matcherName` is specified it only returns `true
` if that particular route was matched.
...
fetchMock = function () { [native code] }
n/a
reset = function () { [native code] }
...
The commonest use case is `fetchMock.mock(matcher, response)`, where `matcher` is a string or regex to match and `response` is a
statusCode, string or object literal. You can also use `fetchMock.once(url ...)` to limit to a single call or `fetchMock.get()`, `
fetchMock.post()` etc. to limit to a method. All these methods are chainable so you can easily define several mocks in a single
test.
## Analysing calls to your mock
`fetchMock.called(matcher)` reports if any calls matched your mock (or leave `matcher` out if you just want to check `fetch` was
called at all). `fetchMock.lastCall()`, `fetchMock.lastUrl()` or `fetchMock.lastOptions()` give you access to the parameters last
passed in to `fetch`. `fetchMock.done()` will tell you if `fetch` was called the expected number of times.
## Tearing down your mock
`fetchMock.reset()` resets the call history. `fetchMock.restore()` will also restore `
fetch()` to its native implementation
## Example
Example with node: suppose we have a file `make-request.js` with a function that calls `fetch`:
```js
module.exports = function makeRequest() {
return fetch("http://httpbin.org/get").then(function(response) {
...
restore = function () { [native code] }
...
#### `restore()`
Chainable method that restores `fetch()` to its unstubbed state and clears all data recorded for its calls.
#### `reset()`
Chainable method that clears all data recorded for `fetch()`'s calls
*Note that `restore()` and `reset()` are both bound to fetchMock, and can be used directly as callbacks e.g. `afterEach(fetchMock
.restore)` will work just fine. There is no need for `afterEach(function () {fetchMock.restore
()})`*
## Analysing how `fetch()` has been called
**For the methods below `matcherName`, if given, should be either the name of a route (see advanced usage below) or equal to `matcher
.toString()` for any unnamed route. You _can_ pass in the original regex or function used as a matcher, but they will be converted
to strings and used to look up values in fetch-mock's internal maps of calls, rather than used as regexes or functions**
#### `called(matcherName)`
Returns a Boolean indicating whether fetch was called and a route was matched. If `matcherName` is specified it only returns `true
` if that particular route was matched.
...