3.2.0 — the revival release
The first release since 3.0.3 (March 2020). Everything merged to master in the intervening years ships here, plus a round of new fixes. The project is under active maintenance again: CI gates every PR (unit matrix on Node 18–24 plus six consumer integration fixtures run against the packed tarball), and releases publish via npm trusted publishing with provenance.
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(sync or async) and its status/headers are preserved. 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) — if your code callsfetch()with no arguments, add a URL - Tests asserting the old synchronous abort throw should switch from
expect(() => fetch(...)).toThrow()toawait expect(fetch(...)).rejects.toThrow() cross-fetchfloor raised to ^3.1.8, closing the vulnerable-transitive-node-fetchreport (#228, #249)promise-polyfilldependency removed (dead code on Node ≥ 12)- The npm tarball no longer ships tooling files (3.0.3 even shipped coverage reports)
Docs
- README overhauled: a prominent warning for the
resetMocks: truefootgun (#81, #78, #104, #202), modern TypeScript setup, Node native-fetch notes, and a recipes section for the perennial questions. CHANGELOG added.
What's next
v4.0.0 will rearchitect around the environment's native fetch (no more replacing global.Response/Request/Headers — the root cause of #218 and the Node 18+ issue cluster), with dual CJS+ESM and self-contained types. It will soak on the next dist-tag before release. Using Vitest? See vitest-fetch-mock.