unstale

npm / jest-fetch-mock

jest-fetch-mock

What changed in jest-fetch-mock 4, from its official release notes, upgrade guides and advisories. Sources checked 2026-10-28.

9 breaking13 new APIs and options2 fixes and other

See which of these apply to your code, ranked, in your agent:

npx @unstale/cli init

@unstale/cli 0.2.9 on npm

jest-fetch-mock 424 changes

Breaking changes 9

  • Resetting mocks now clears registered routes too.

    4.2.0release notes

  • Queued mockResponseOnce responses and mockReject/mockAbort take precedence over routes; matching routes outrank the ambient default and conditional gate, including under dontMock().

    4.2.0release notes

  • disableMocks() now restores the environment's original fetch.

    4.0.0release notes

  • In environments with fetch primitives, mocked Responses are native responses and the package no longer replaces global fetch classes; environments without them receive only the missing cross-fetch globals.

    4.0.0release notes

  • The minimum supported Jest version is 28; older stacks should stay on 3.2.0.

    4.0.0release notes

  • The minimum supported Node version is 18; older stacks should stay on 3.2.0.

    4.0.0release notes

  • In Node environments, relative URLs resolve against http://localhost/ for match predicates.

    4.0.0release notes

  • Under Node types, response.json() is typed as Promise<unknown>.

    4.0.0release notes

  • Definitions are self-contained, no longer require @types/jest or force the dom lib, and take ambient fetch types from dom or @types/node ≥ 18.

    4.0.0release notes

New APIs and options 13

  • Empty the registered route registry.

    4.2.0release notes

  • Register routes using URL strings, RegExp, or request predicates, with responses accepted by mockResponse. Routes coexist, and the first registered match wins.

    4.2.0release notes

  • Register a route that is consumed by its first match.

    4.2.0release notes

  • The Response wrapper exposes the error static for use in mocked responses.

    4.1.0release notes

  • On native fetch, the Response wrapper exposes the json static.

    4.1.0release notes

  • The Response wrapper exposes the redirect static for use in mocked responses.

    4.1.0release notes

  • A createFetchMock(jest) factory enables setups using injectGlobals: false or @jest/globals.

    4.0.0release notes

  • An exports map with a ./ wildcard escape hatch is available alongside ESM wrappers.

    4.0.0release notes

  • Sets default response initialization, such as JSON headers, merged under every mock.

    4.0.0release notes

  • Adds a reassignable passthrough target for real fetch requests.

    4.0.0release notes

  • Adds fetchMock.usingNativeFetch.

    4.0.0release notes

  • A dependency-free factory entry is available for injectGlobals: false and @jest/globals setups.

    4.0.0release notes

  • A setup entry provides a one-line setupFilesAfterEnv configuration.

    4.0.0release notes

Fixes and other changes 2

  • Timeout aborts reject with TimeoutError, and custom abort reasons pass through.

    4.0.0release notes

  • When setup runs in setupFilesAfterEnv, resetMocks: true automatically re-arms the fetch mock, preventing fetch from returning undefined.

    4.0.0release notes