npm jest-fetch-mock 3.2.0-beta.2

latest releases: 4.0.0-beta.1, 3.2.0
2 hours ago

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 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.
  • 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)
  • cross-fetch floor raised to ^3.1.8 (patched transitive node-fetch) (#228, #249)
  • promise-polyfill dependency 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.

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

NewReleases is sending notifications on new releases.