npm / jest-fetch-mock
jest-fetch-mock
What changed in jest-fetch-mock 4, from its official release notes, upgrade guides and advisories. Sources checked 2026-10-28.
9 breaking13 new APIs and options2 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initjest-fetch-mock 424 changes
Breaking changes 9
Resetting mocks now clears registered routes too.
Queued mockResponseOnce responses and mockReject/mockAbort take precedence over routes; matching routes outrank the ambient default and conditional gate, including under dontMock().
disableMocks() now restores the environment's original fetch.
In environments with fetch primitives, mocked Responses are native responses and the package no longer replaces global fetch classes; environments without them receive only the missing cross-fetch globals.
The minimum supported Jest version is 28; older stacks should stay on 3.2.0.
The minimum supported Node version is 18; older stacks should stay on 3.2.0.
In Node environments, relative URLs resolve against http://localhost/ for match predicates.
Under Node types, response.json() is typed as Promise<unknown>.
Definitions are self-contained, no longer require @types/jest or force the dom lib, and take ambient fetch types from dom or @types/node ≥ 18.
New APIs and options 13
Empty the registered route registry.
Register routes using URL strings, RegExp, or request predicates, with responses accepted by mockResponse. Routes coexist, and the first registered match wins.
Register a route that is consumed by its first match.
The Response wrapper exposes the error static for use in mocked responses.
On native fetch, the Response wrapper exposes the json static.
The Response wrapper exposes the redirect static for use in mocked responses.
A createFetchMock(jest) factory enables setups using injectGlobals: false or @jest/globals.
An exports map with a ./ wildcard escape hatch is available alongside ESM wrappers.
Sets default response initialization, such as JSON headers, merged under every mock.
Adds a reassignable passthrough target for real fetch requests.
Adds fetchMock.usingNativeFetch.
A dependency-free factory entry is available for injectGlobals: false and @jest/globals setups.
A setup entry provides a one-line setupFilesAfterEnv configuration.
Fixes and other changes 2
Timeout aborts reject with TimeoutError, and custom abort reasons pass through.
When setup runs in setupFilesAfterEnv, resetMocks: true automatically re-arms the fetch mock, preventing fetch from returning undefined.