Socket
Socket
Sign inDemoInstall

fetch-mock-jest

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-mock-jest - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

2

package.json
{
"name": "fetch-mock-jest",
"version": "0.1.2",
"version": "0.1.3",
"description": "",

@@ -5,0 +5,0 @@ "main": "fetch-mock-jest.js",

# fetch-mock-jest
Wrapper around fetch-mock to make working with jest a jolly old joy.
Wrapper around [fetch-mock](http://www.wheresrhys.co.uk/fetch-mock) - a comprehensive, isomorphic mock for the [fetch api](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) - which provides an interface that is more idiomatic when working in [jest](https://jestjs.io)
# Installation
`npm install -D fetch-mock-jest`
## global fetch

@@ -14,3 +16,3 @@

```
jest.mock('node-fetch', () => require('fetch-mock-jest'))
jest.mock('node-fetch', () => require('fetch-mock-jest').sandbox())
const fetchMock = require('node-fetch')

@@ -21,9 +23,25 @@ ```

`expect(fetchMock)` can be inspected using all the built in jest function inspection assertions. `fetch.mockClear()` and `fetch.mockReset()` shodul aslo work (however all other jest mock setup methods are disabled as fetch-mock's own methdos should always be used)
All the built in jest function inspection assertions can be used, e.g. `expect(fetchMock).toHaveBeenCalledWith('http://example.com')`.
In addition, the following work:
`expect(fetchMock).toHaveLastFetched(url, options)`
`expect(fetchMock).toHaveNthFetched(n, url, options)`
`expect(fetchMock).toHaveFetchedTimes(times, url, options)`
`expect(fetchMock).toBeDone(matcher)`
, proxying through to the similar fetchMock methods.
`fetch.mockClear()` can be used to reset the call history
`fetch.mockReset()` can be used to remove all configured mocks
All other jest methods for configuring mock functions are disabled as fetch-mock's own methods should always be used
`fetchMock.mock.calls` and `fetchMock.mock.results` are also exposed, giving access to manually inspect the calls.
The following custom jest expectation methods, proxying through to `fetch-mock`'s inspection methods are also available. They can all be prefixed with the `.not` helper for negative assertions.
- `expect(fetchMock).toHaveLastFetched(filter, options)`
- `expect(fetchMock).toHaveNthFetched(n, filter, options)`
- `expect(fetchMock).toHaveFetchedTimes(n, filter, options)`
- `expect(fetchMock).toBeDone(filter)`
`filter` and `options` are the same as those used by [`fetch-mock`'s inspection methods](http://www.wheresrhys.co.uk/fetch-mock/#api-inspectionfundamentals)
### TODO
These would also be useful jest extensions:
- `toHaveFetched`
- `toHaveRespondedWith({status, body, headers})` (using objectMatching semantics)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc