4.0.0 — native fetch, no more global stomping
jest-fetch-mock 4.0 no longer replaces the global fetch classes with node-fetch implementations. In environments that provide fetch primitives (jest-environment-node, Jest 28+), mocked Responses are real native (undici) responses — instanceof works, streams and FormData behave, and nothing your tests didn't ask for is touched. Where the environment has none (jest-environment-jsdom), the cross-fetch fallback fills exactly the missing globals, as it always did.
Every 3.x API is unchanged. The 3.x unit suite and seven consumer integration fixtures (React + Testing Library, TypeScript strict under three tsconfigs, jsdom, Jest 30, native-fetch hosts, a real-HTTP-server passthrough e2e) pass against 4.0 unmodified.
Added
createFetchMock(jest)factory + dependency-freejest-fetch-mock/factoryentry —injectGlobals: false/@jest/globalssetups finally work (#248)"setupFilesAfterEnv": ["jest-fetch-mock/setup"]one-linerresetMocks: trueauto-re-arm — the years-old "fetch returns undefined" footgun (#78, #81, #202) is gone when setup runs insetupFilesAfterEnvAbortSignal.timeout()rejects with itsTimeoutError; custom abort reasons pass through (#242)fetchMock.defaultResponseInit— default init (e.g. JSON headers) merged under every mock (#166)fetchMock.realFetch(reassignable passthrough target) andfetchMock.usingNativeFetch- ESM wrappers +
exportsmap with a./*escape hatch
Changed (breaking)
- Floors: Node ≥ 18, Jest ≥ 28 — stay on 3.2.0 for older stacks
disableMocks()restores the environment's originalfetch- Self-contained TypeScript definitions: no
@types/jestrequirement, no forceddomlib — ambient fetch types come fromlib: ["dom"]or@types/node≥ 18; under node typesresponse.json()is honestlyPromise<unknown> - Relative URLs in node environments resolve against
http://localhost/for match predicates domexceptiondependency removed
Migration guide: https://github.com/jefflau/jest-fetch-mock#migrating-from-3x • CHANGELOG