The modernization beta — please test: npm install -D jest-fetch-mock@next
The headline: jest-fetch-mock no longer replaces global fetch classes with node-fetch implementations. In environments that provide fetch primitives (jest-environment-node, Jest 28+), your mocked Responses are real native responses, instanceof works, and nothing your tests didn't ask for is touched. Where the environment has none (jsdom), the cross-fetch fallback fills exactly the missing globals, as before.
Added
createFetchMock(jest)factory + dependency-freejest-fetch-mock/factoryentry (injectGlobals: false/@jest/globalssupport)"setupFilesAfterEnv": ["jest-fetch-mock/setup"]one-linerresetMocks: trueauto-re-arm — the years-old "fetch returns undefined" footgun (#78, #81, #202) is fixed when setup runs insetupFilesAfterEnvAbortSignal.timeout()rejects with itsTimeoutError; custom abort reasons pass through (#242)fetchMock.defaultResponseInit— default headers/init 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 (3.2.0 remains for older stacks)
disableMocks()restores the environment's original fetch- TypeScript definitions are self-contained: no
@types/jestrequirement (#248), no forceddomlib (#201) — you need ambient fetch types fromlib: ["dom"]or@types/node≥ 18, and under node typesresponse.json()is honestlyPromise<unknown> - Relative URLs in node environments resolve against
http://localhost/for matching domexceptiondependency removed
Unchanged
Every 3.x API, alias, chaining behavior, once-queue semantic, and abort message. The full 3.x suite and all seven consumer integration fixtures pass against this beta unmodified.
Migration guide: https://github.com/jefflau/jest-fetch-mock#migrating-from-3x — feedback on #263, please.