Release candidate for 3.2.0 — the first release since 3.0.3 (March 2020). Please help test: npm install -D jest-fetch-mock@next. Supersedes 3.2.0-beta.1.
Added
- Pass a
Responseobject directly tomockResponse/mockResponseOnce/once/mockResponsesand the conditional mocks — including binary (Buffer) bodies (#223, thanks @alexkolson). Response functions may also return aResponse. URLobjects and other stringifiables accepted as fetch input (#193)- Synchronous response functions — no need to return a promise (#145)
- Mock
redirectedresponses via thecounterinit param (#168) enginesfield declaring the Node ≥ 12 floor
Fixed
- TypeScript definitions work with modern
@types/nodeagain — no moreNodeJS.Globalimport (#184, #201, #248) fetch()with an already-aborted signal rejects (per the fetch spec) instead of throwing synchronously, so it is catchable (#237)fetch.isMockingreturns a plain boolean afterresetMocks()(#183)DOMExceptionpolyfilled in Node environments —mockAbortworks underjest-environment-node(#159)dontMockIfpredicates now receive the request method/headers, matchingdoMockIf- Conditional mock callbacks may return synchronously in TypeScript (#220)
Changed
- TypeScript: fetch's
inputargument is required, matching the DOM signature (#206, #207) cross-fetchfloor raised to ^3.1.8 (patched transitivenode-fetch) (#228, #249)promise-polyfilldependency removed (dead code on Node ≥ 12)- Publishing now via npm trusted publishing with provenance; the tarball no longer ships tooling files
Internal
- Test suite: 64 → 98 tests, ~99% coverage enforced; new six-fixture integration suite (React/Testing Library, TS strict, Jest 30, native-fetch host, real-server passthrough e2e) gates every release
Full details in the CHANGELOG.