mswjs /msw

The industry standard for API mocking in JavaScript.

★ 18,351⑂ 651👁 61⑃ 1,044● 1,283▤ 278
TypeScriptMITCreated 2018-11-13mswjs.io
Download: v3.0.6v3.0.6 ↓3.0.62026-11-15
+0
Daily
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

Discussions

Latest release

v3.0.6 v3.0.6 2026-11-15
v3.0.6 (2026-11-15)

 Bug Fixes

- preserve optional path parameters and pipes in handler paths (2838) (022df00e958a7e2f2c04d26da10438b844d727b3) @kettanaito

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON