Skip to content

Bump jest-fetch-mock from 3.0.3 to 4.2.0#138

Open
dependabot[bot] wants to merge 1 commit into
masterfrom
dependabot/npm_and_yarn/jest-fetch-mock-4.2.0
Open

Bump jest-fetch-mock from 3.0.3 to 4.2.0#138
dependabot[bot] wants to merge 1 commit into
masterfrom
dependabot/npm_and_yarn/jest-fetch-mock-4.2.0

Conversation

@dependabot

@dependabot dependabot Bot commented on behalf of github Jul 16, 2026

Copy link
Copy Markdown
Contributor

Bumps jest-fetch-mock from 3.0.3 to 4.2.0.

Release notes

Sourced from jest-fetch-mock's releases.

4.2.0 — route-based mocking

The most-requested feature finally lands (#171, filed in 2020): registered routes that coexist.

fetchMock
  .route('https://api.example.com/session', JSON.stringify({ user: 'jeff' }))
  .route(/\/teams$/, JSON.stringify([{ id: 42 }]))
  .routeOnce('https://api.example.com/login', '', { status: 401 })
  • Matchers are the familiar shapes (URL string, RegExp, (request) => boolean); responses are everything mockResponse accepts (string, Response, sync/async function). First registered match wins.
  • routeOnce() is consumed by its first match; clearRoutes() empties the registry; resetMocks() clears routes too.
  • Precedence: a queued mockResponseOnce outranks routes for its call; a matching route outranks the ambient default and the conditional gate — so routes fire even under dontMock(), making "mock these endpoints, let everything else hit the network" a one-liner each.
  • mockReject()/mockAbort() override routes. Existing behavior is untouched — every pre-4.2 test passes unmodified.

Docs: RoutesCHANGELOG

Also in this release: the publish workflow no longer self-upgrades npm on the runner (it corrupted itself mid-run once; Node 24's bundled npm already supports trusted publishing).

4.1.0

Small follow-up to 4.0.0:

Added

  • fetchMock.Response.redirect(), .error() and — on native fetch — .json() statics are exposed through the Response wrapper (#191): fetchMock.mockResponseOnce(fetchMock.Response.redirect('https://moved.test/', 302))

Docs

  • README fully aligned with the 4.0 architecture (native-primitives intro, setupFilesAfterEnv one-liner as the recommended setup, rewritten resetMocks note around the auto-re-arm, self-contained TypeScript notes, redirected mocking documented for every environment, realFetch in the conditional-mocking example) — this is the version shown on the npm package page

Also today: the issue tracker was cleared — every open issue received a verdict and a reply. Remaining open by intent: #171 (stacking mockIf matchers, the flagship 4.x feature request — design input welcome) and #233 (awaiting reproduction). CHANGELOG

4.0.0 — native fetch, no more global stomping

jest-fetch-mock 4.0 no longer replaces the global fetch classes with node-fetch implementations. In environments that provide fetch primitives (jest-environment-node, Jest 28+), mocked Responses are real native (undici) responses — instanceof works, streams and FormData behave, and nothing your tests didn't ask for is touched. Where the environment has none (jest-environment-jsdom), the cross-fetch fallback fills exactly the missing globals, as it always did.

Every 3.x API is unchanged. The 3.x unit suite and seven consumer integration fixtures (React + Testing Library, TypeScript strict under three tsconfigs, jsdom, Jest 30, native-fetch hosts, a real-HTTP-server passthrough e2e) pass against 4.0 unmodified.

Added

  • createFetchMock(jest) factory + dependency-free jest-fetch-mock/factory entry — injectGlobals: false / @jest/globals setups finally work (#248)
  • "setupFilesAfterEnv": ["jest-fetch-mock/setup"] one-liner
  • resetMocks: true auto-re-arm — the years-old "fetch returns undefined" footgun (#78, #81, #202) is gone when setup runs in setupFilesAfterEnv
  • AbortSignal.timeout() rejects with its TimeoutError; custom abort reasons pass through (#242)
  • fetchMock.defaultResponseInit — default init (e.g. JSON headers) merged under every mock (#166)
  • fetchMock.realFetch (reassignable passthrough target) and fetchMock.usingNativeFetch
  • ESM wrappers + exports map with a ./* escape hatch

Changed (breaking)

  • Floors: Node ≥ 18, Jest ≥ 28 — stay on 3.2.0 for older stacks
  • disableMocks() restores the environment's original fetch
  • Self-contained TypeScript definitions: no @types/jest requirement, no forced dom lib — ambient fetch types come from lib: ["dom"] or @types/node ≥ 18; under node types response.json() is honestly Promise<unknown>
  • Relative URLs in node environments resolve against http://localhost/ for match predicates
  • domexception dependency removed

... (truncated)

Changelog

Sourced from jest-fetch-mock's changelog.

4.2.0 (2026-07-08)

Added

  • Route-based mocking (#171): fetchMock.route(urlOrPredicate, bodyOrFunction?, init?) and routeOnce(...) register matcher→response pairs that coexist, plus clearRoutes(). First registered match serves. Precedence: queued once-responses > routes > the conditional gate and ambient mockResponse; a matching route fires even under dontMock() (mock only known endpoints, let the rest hit the network); mockReject/mockAbort override routes. resetMocks() clears routes.

#171: jefflau/jest-fetch-mock#171

4.1.0 (2026-07-08)

Added

  • fetchMock.Response.redirect(), .error() and (on native fetch) .json() statics are exposed through the Response wrapper (#191)

Docs

  • README fully aligned with 4.0 (native-primitives intro, setupFilesAfterEnv one-liner as the primary setup, rewritten resetMocks note around the auto-re-arm, self-contained types, redirected mocking works everywhere, realFetch in examples)

#191: jefflau/jest-fetch-mock#191

4.0.0 (2026-07-08)

The modernization release (published as 4.0.0-beta.1 earlier the same day; identical content). Headline: jest-fetch-mock no longer replaces the global fetch classes with node-fetch implementations.

Changed (breaking)

  • Native fetch primitives. In environments that provide fetch/Response/Request/Headers (jest-environment-node has since Jest 28), the mock builds on them and never replaces them — fixing the whole "the global Response broke my unrelated test" cluster (#218) and making instanceof, streams, FormData, and Response.json() behave natively. Where the environment has none (jest-environment-jsdom), the cross-fetch fallback engages exactly as before, filling only the missing globals.
  • disableMocks() restores the environment's original fetch (previously it installed cross-fetch's).
  • Support floor: Node ≥ 18, Jest ≥ 28. The 3.x line remains available for older stacks.
  • TypeScript definitions are self-contained: no @types/jest requirement (works with @jest/globals-only setups, #248) and no forced dom lib (#201). Ambient Response/Request types must come from your lib: ["dom"] or @types/node ≥ 18 — in practice, every Jest project has one of these.
  • Relative URL inputs in native mode resolve against http://localhost/ for matching purposes (the native Request requires absolute URLs); jsdom-fallback behavior is unchanged.
  • domexception dependency removed (native since Node 17).

Added

  • createFetchMock(jest) factory, also available from the dependency-free entry jest-fetch-mock/factory — build an instance with an explicitly-passed jest object, for injectGlobals: false / @jest/globals setups.
  • "setupFiles": ["jest-fetch-mock/setup"] one-liner setup.
  • resetMocks: true auto-re-arm (#78, #81, #202): when enableMocks() runs where beforeEach exists (setupFilesAfterEnv or a test file), the default implementation is re-armed after Jest's config-driven reset. The years-old footgun is fixed — move your setup file to setupFilesAfterEnv to benefit.
  • AbortSignal.timeout() rejections carry the signal's TimeoutError; custom abort reasons pass through as-is (#242). Plain aborts keep the historical AbortError message.
  • fetchMock.defaultResponseInit — an init merged under every mocked response, e.g. default JSON headers (#166).
  • fetchMock.realFetch — the implementation unmatched requests pass through to, reassignable in tests; fetchMock.usingNativeFetch tells you which mode engaged.
  • ESM wrapper and an exports map (with a ./* escape hatch so deep imports keep working); url and counter MockParams are patched onto native responses so response.url/response.redirected mocking still works.

Unchanged

Every 3.x API call, alias, chaining behavior, once-queue semantics, and the abort error message. The whole 3.x test suite and all seven consumer integration fixtures run green against 4.0.

3.2.0 (2026-07-08)

First release since 3.0.3 (March 2020). Everything merged to master in the intervening years ships in this release, plus a round of new fixes. Version 3.1.0 was tagged in 2024 but never published to npm; its contents are included here.

... (truncated)

Commits
Maintainer changes

This version was pushed to npm by GitHub Actions, a new releaser for jest-fetch-mock since your current version.


@dependabot dependabot Bot added dependencies Pull requests that update a dependency file javascript Pull requests that update javascript code labels Jul 16, 2026
Bumps [jest-fetch-mock](https://github.com/jefflau/jest-fetch-mock) from 3.0.3 to 4.2.0.
- [Release notes](https://github.com/jefflau/jest-fetch-mock/releases)
- [Changelog](https://github.com/jefflau/jest-fetch-mock/blob/master/CHANGELOG.md)
- [Commits](https://github.com/jefflau/jest-fetch-mock/commits/v4.2.0)

---
updated-dependencies:
- dependency-name: jest-fetch-mock
  dependency-version: 4.2.0
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
@dependabot
dependabot Bot force-pushed the dependabot/npm_and_yarn/jest-fetch-mock-4.2.0 branch from 9db8047 to f70fedb Compare July 16, 2026 04:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file javascript Pull requests that update javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants