npm jest-fetch-mock 3.2.0
3.2.0 — the revival release

latest release: 4.0.0-beta.1
2 hours ago

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 Response object directly to mockResponse/mockResponseOnce/once/mockResponses and the conditional mocks — including binary (Buffer) bodies (#223, thanks @alexkolson). Response functions may also return a Response (sync or async) and its status/headers are preserved.
  • URL objects and other stringifiables accepted as fetch input (#193)
  • Synchronous response functions — no need to return a promise (#145)
  • Mock redirected responses via the counter init param (#168)
  • engines field declaring the Node ≥ 12 floor

Fixed

  • TypeScript definitions work with modern @types/node again — no more NodeJS.Global import (#184, #201, #248)
  • fetch() with an already-aborted signal rejects (per the fetch spec) instead of throwing synchronously, so it is catchable (#237)
  • fetch.isMocking returns a plain boolean after resetMocks() (#183)
  • DOMException polyfilled in Node environments — mockAbort works under jest-environment-node (#159)
  • dontMockIf predicates now receive the request method/headers, matching doMockIf
  • Conditional mock callbacks may return synchronously in TypeScript (#220)

Changed

  • TypeScript: fetch's input argument is required, matching the DOM signature (#206, #207) — if your code calls fetch() with no arguments, add a URL
  • Tests asserting the old synchronous abort throw should switch from expect(() => fetch(...)).toThrow() to await expect(fetch(...)).rejects.toThrow()
  • cross-fetch floor raised to ^3.1.8, closing the vulnerable-transitive-node-fetch report (#228, #249)
  • promise-polyfill dependency 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: true footgun (#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.

Don't miss a new jest-fetch-mock release

NewReleases is sending notifications on new releases.