
msw-fetch-mock: Undici-Style Fetch Mocking for MSW
Originally published at recca0120.github.io When writing frontend or Node.js tests, mocking HTTP requests is practically mandatory. But choosing a mock solution is overwhelming: MSW , nock , fetch-mock , jest-fetch-mock… each has a different API style, interception level, and environment support. If you work on both Cloudflare Workers and Node.js projects, you'll find the mock APIs are completely different and test code can't be shared. msw-fetch-mock solves exactly this: it provides the same API style as undici's MockAgent and Cloudflare Workers' fetchMock , with MSW handling network-level interception underneath. One API, every environment. Why Existing Solutions Fall Short Here are the 6 mainstream HTTP mock solutions today: Solution npm Weekly Downloads Interception Level Node native fetch Browser Maintenance MSW ~10.5M Service Worker / Node internals ✅ ✅ Active nock ~5.5M Node http module ❌ ❌ Active fetch-mock ~1.0M Replaces globalThis.fetch ✅ ✅ Active jest-fetch-mock ~1.3M Replac
Continue reading on Dev.to
Opens in a new tab




