![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@fetch-mock/jest
Advanced tools
A wrapper for fetch-mock that improves the developer experience when working with jest. It provides the following:
expect
with convenience methods allowing for expressive tests such as expect(fetchMock).toHavePosted('http://example.com', {id: 'test-id'})
.clearAllMocks()
.@fetch-mock/jest requires either of the following to run:
fetch
API, via one of the following:
fetch
APInpm i -D @fetch-mock/jest
import fetchMock, { manageFetchMockGlobally } from '@fetch-mock/jest';
import { jest } from '@jest/glonals';
manageFetchMockGlobally(jest); // optional
An instance of @fetch-mock/core, with the following methods added:
Clears all call history from the mocked fetch
implementation.
Clears all call history from the mocked fetch
implementation and removes all routes (including fallback routes defined using .spy()
or .catch()
) with the exception of sticky routes. To remove these, pass in the includeSticky: true
option. FOr more fine grained control over fallback routes and named routes please use fetchMock.removeRoutes()
Calls mockReset()
and additionally restores global fetch to its unmocked implementation.
Hooks fetchMock up to jest's global mock management so that
jest.clearAllMocks()
will call fetchMock.mockClear()
jest.resetAllMocks()
will call fetchMock.mockReset()
jest.restoreAllMocks()
will call fetchMock.mockRestore()
Note that these will not clear any sticky routes added to fetchMock. You will need to make an additional call to fetchMock.removeRoutes({includeSticky: true})
.
These are added to jest automatically and are available on any expect call that is passed fetchMock as an argument. Their behaviour is similar to the jest expectation methods mentioned in the comments below
expect(fetchMock).toHaveFetched(filter, options); // .toHaveBeenCalled()/.toHaveBeenCalledWith()
expect(fetchMock).toHaveLastFetched(filter, options); // .toHaveBeenLastCalledWith()
expect(fetchMock).toHaveNthFetched(n, filter, options); // .toHaveBeenNthCalled()/.toHaveBeenNthCalledWith()
expect(fetchMock).toHaveFetchedTimes(n, filter, options); // .toHaveBeenCalledTimes()
expect(fetchMock).toBeDone(filter);
filter
and options
are the same as those used by fetchMock.callHistory.calls()
..not
helper for negative assertions. e.g. expect(fetchMock).not.toBeDone('my-route')
Fetched
can be replaced by any of the following verbs to scope to a particular method:
expect(fetchMock).toHaveDeleted('http://example.com/user/1')
FAQs
jest wrapper for fetch-mock
The npm package @fetch-mock/jest receives a total of 787 weekly downloads. As such, @fetch-mock/jest popularity was classified as not popular.
We found that @fetch-mock/jest demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.