An undici-style fetch mock API built on top of MSW (Mock Service Worker) for testing. Version 0.6.1 supports Node.js (>=18), browser, and native (no MSW dependency) environments via subpath exports. It provides a familiar fluent API similar to Cloudflare Workers' fetchMock or Node.js undici's MockAgent. Key differentiators: integrates seamlessly with MSW, supports both MSW v1 (via /legacy) and v2, and allows sharing existing MSW servers. Peer dependency on MSW ^1.0.0 or ^2.12.7. Active development with CI, weekly downloads ~500.
npm install msw-fetch-mockNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows basic setup and usage of fetchMock for mocking an HTTP GET request in a test suite, including activation, cleanup, and assertion.
Use createFetchMock(server) to share an existing MSW server.
Upgrade to MSW v2 and use the main entry or /node subpath.
Set onUnhandledRequest to 'warn' or 'bypass' if needed.
Update Node.js to 18+.
Use explicit subpaths like 'msw-fetch-mock/node' for clarity.
Use createFetchMock(server) to share the existing server.
Use import syntax or set type: 'module' in package.json.
Use import { fetchMock } from 'msw-fetch-mock'.Install msw or use import { fetchMock } from 'msw-fetch-mock/native'.