mswjs /msw
The industry standard for API mocking in JavaScript.
★ 18,351⑂ 651👁 61⑃ 1,044● 1,283▤ 278
+0
日增长
18,351
stars
651
forks
61
watchers
1,044
prs
1,283
issues
278
releases
README
Mock Service Worker The industry standard for API mocking in JavaScript. Join our Discord server Features - Seamless. A dedicated layer of requests interception at your disposal. Keep your application's code and tests unaware of whether something is mocked or not. - Deviation-free. Request the same production resources and test the actual behavior of your app. Augment an existing API, or design it as you go when there is none. - Familiar & Powerful. Use Express-like routing syntax to intercept requests. Use parameters, wildcards, and regular expressions to match requests, and respond with necessary status codes, headers, cookies, delays, or completely custom resolvers. --- "_I found MSW and was thrilled that not only could I still see the mocked responses in my DevTools, but that the mocks didn't have to be written in a Service Worker and could instead live alongside the rest of my app. This made it silly easy to adopt. The fact that I can use it for testing as well makes MSW a huge productivity booster._" — Kent C. Dodds Documentation This README will give you a brief overview of the library, but there's no better place to start with Mock Service Worker than its official documentation. - Documentation - Quick start - FAQ Examples - See the list of Usage examples Courses We've partnered with Egghead to bring you quality paid materials to learn the best practices of API mocking on the web. Please give them a shot! The royalties earned from them help sustain the project's development. Thank you. - 🚀 Mocking REST and GraphQL APIs with Mock Service Worker - 🔌 Mocking (and testing) WebSocket APIs with Mock Service Worker Browser - Learn more about using MSW in a browser - setupWorker API How does it work? In-browser usage is what sets Mock Service Worker apart from other tools. Utilizing the Service Worker API, which can intercept requests for the purpose of caching, Mock Service Worker responds to intercepted requests with your mock definition on the network level. This way your application knows nothing about the mocking. Take a look at this quick presentation on how Mock Service Worker functions in a browser: How is it different? - This library intercepts requests on the network level, which means _after_ they have been performed and "left" your application. As a result, the entirety of your code runs, giving you more confidence when mocking; - Imagine your application as a box. Every API mocking library out there opens your box and removes the part that does the request, placing a blackbox in its stead. Mock Service Worker leaves your box intact, 1-1 as it is in production. Instead, MSW lives in a separate box next to yours; - No more stubbing of fetch, axios, react-query, you-name-it; - You can reuse the same mock definition for the unit, integration, and E2E testing. Did we mention local development and debugging? Yep. All running against the same network description without the need for adapters or bloated
Top issues
#744MSW leaves cypress component test runner in a loop62 comments · 2021-05-22#1627Chrome reloads infinitely when `serviceWorker.options.scope` is set10 comments · 2023-05-25#2401MSW + React + Vite: Failed to HMR Update if MSW active7 comments · 2024-12-24#2435Support custom WebSocket clients6 comments · 2025-02-20#2815Request headers parsed from the socket lose `Cookie` (and other forbidden headers) in browser-like environments4 comments · 2026-10-13#420Support proper logger4 comments · 2020-10-09#2827Unhandled InvalidStateError from registration.update() in Firefox on fast navigation3 comments · 2026-10-29#2525Not intercepting socket.io if it gets imported before MSW3 comments · 2025-06-05
Discussions
#2839Open-source verification stack for AI-assisted TypeScript apps (headless Playwright QA, 92-rule security scanner & 72-rule UI linter)0 comments · 2026-11-14#2823onUnhandledFrame: `frame.data` is unknown (`frame.protocol` check)1 comments · 2026-10-23#2817Updating msw to v3, tests now fail because of missing matching OPTIONS request handler2 comments · 2026-10-16#2814MSW intregration with Vite DevTools0 comments · 2026-10-13#2813🎨 Introduce Mocking GUI: A Visual Control Panel for MSW Handlers0 comments · 2026-10-13#2800Browser integration docs page is 4041 comments · 2026-10-01#2787Vitest Browser Mode in Vitest 5 no longer serves `/mockServiceWorker.js` automatically1 comments · 2026-09-18#2775What evidence should justify recommending a network mock for a PR?3 comments · 2026-08-25
Latest release
v3.0.6 v3.0.6 2026-11-15v3.0.6 (2026-11-15) Bug Fixes - preserve optional path parameters and pipes in handler paths (2838) (022df00e958a7e2f2c04d26da10438b844d727b3) @kettanaito