
MSW Review
- MIT license
- Free to use forever
- No commercial or cloud product
- Installed as an npm dependency
- Funded by GitHub Sponsors
- No licensing costs
- No paid tier or subscription
- Pure library, no hosted service
- MIT-licensed and source-auditable
- Created in 2018 by Artem Zakharchenko
- Maintained by the mswjs community
- Funded by GitHub Sponsors
- 18,000+ GitHub stars
Overview
MSW, short for Mock Service Worker, is an API mocking library for the browser and Node.js. It intercepts outgoing network requests, observes them, and responds with mocked responses, but it does so at the network level, after the request leaves your application. In the browser it uses the Service Worker API to intercept requests, and in Node.js it uses low-level request interceptors rather than patching fetch or XHR. The practical effect is that your application makes real fetch or axios calls and does not know it is being mocked. It was created in 2018 by Artem Zakharchenko and is maintained by the mswjs community, with the current release at version 2.14.6.
MSW is not a standalone mock server like WireMock. It runs inside your app or test process as a dependency, so traditional deployment does not apply. You install it, register a worker in the browser or a server listener in Node, and define request handlers in code. The docs frame it as a single source of truth for network behavior, reused across testing, local development, Storybook, and demos.
It is for frontend and full-stack JavaScript and TypeScript developers and teams, including React, Vue, Angular, Svelte, Next.js, Remix, and React Native developers, plus anyone testing code that makes API calls. It is widely treated as the de-facto standard for frontend API mocking.
The core value is that the same mock handlers are reusable everywhere. The same definitions drive an integration test in Vitest or Jest, a browser end-to-end test in Playwright or Cypress, a Storybook story, and local development against a not-yet-built backend. Because interception happens at the network level, mocks are request-library-agnostic and require no changes to application code.
What makes MSW distinct is its Service-Worker-based interception model, which mocks at the network boundary rather than stubbing modules, so mocked requests appear in browser DevTools as real network traffic. It supports REST, GraphQL, WebSocket, and Server-Sent Events mocking in one library, and it is officially recommended by major testing tooling. It is free under the MIT license, so buyers should weigh its JavaScript-only scope and in-process design against its flexibility and reach.
Key Featuresโ
Service Worker interceptionโ
In the browser, MSW intercepts network requests via the Service Worker API, and mocked responses appear as real network entries in DevTools. This makes mocking transparent to the application.
Node.js interceptionโ
In Node, MSW intercepts requests through low-level interceptors rather than patching fetch or XHR. This works the same way across server-side and test environments.
REST and HTTP mockingโ
The http handlers, such as http.get and http.post, provide Express-like routing for REST APIs. This covers the most common API style.
GraphQL mockingโ
The graphql handlers mock queries and mutations by operation name. This serves GraphQL-based applications.
WebSocket mockingโ
The ws handlers mock WebSocket connections per the WHATWG standard, added in version 2.6.0. This extends mocking to real-time APIs.
Server-Sent Eventsโ
MSW also mocks Server-Sent Events. This covers streaming APIs alongside REST and GraphQL.
Request matchingโ
Handlers match on path parameters, wildcards, regex, query strings, and request body. This precisely targets specific requests.
Response resolversโ
Response resolvers return mocked responses with custom status codes, headers, cookies, and delays. This produces realistic responses.
Fetch API standardโ
Since version 2.0, handlers use standard Request and Response objects, replacing the older request, response, and context API. This aligns MSW with web standards.
Request-library agnosticโ
Because interception is at the network level, MSW works with fetch, axios, and any HTTP client, plus data libraries on top. This avoids coupling mocks to a request library.
Reusable handlersโ
The same handlers run across the browser, Node, and test frameworks. This lets teams write mocks once and use them everywhere.
Passthrough and one-time handlersโ
Passthrough lets selected requests hit the real network, and one-time handlers respond only once for sequencing. These support nuanced test scenarios.
Lifecycle events and loggingโ
Lifecycle events such as request start and response mocked, plus console logging and unhandled-request warnings, support instrumentation. These aid debugging and assertions.
Best Selling Pointsโ
Network-level interceptionโ
MSW intercepts at the network boundary rather than stubbing fetch or axios. This makes mocks request-library agnostic.
Write once, run everywhereโ
The same handlers run in the browser, Node, and all test runners. This removes duplicated mock logic.
Framework-agnosticโ
MSW works across React, Vue, Angular, Svelte, Next.js, Remix, and React Native. It is not tied to one framework.
REST, GraphQL, WebSocket, and SSEโ
A single library covers REST, GraphQL, WebSocket, and Server-Sent Events. This consolidates API mocking.
Recommended by major toolingโ
React Testing Library and the broader testing ecosystem recommend MSW. It is the de-facto standard for frontend API mocking.
Free and open sourceโ
MSW is MIT-licensed with no cost or lock-in. It is funded by sponsorships.
Supported Integrationsโ
MSW integrates across API types, JavaScript environments, test runners, UI frameworks, and tooling.
Connect MSW across API types, environments, and the JavaScript testing ecosystem.
- REST / HTTP
- GraphQL
- WebSocket
- Server-Sent Events
- Browser & Node
- Test Runners
API Types
- REST / HTTP
- GraphQL
- WebSocket
- Server-Sent Events
Environments
- Browser (Service Worker)
- Node.js (interceptors)
- React Native
- jsdom and happy-dom
Test Frameworks
- Jest
- Vitest
- Playwright
- Cypress
- Testing Library
UI Frameworks
- React
- Vue
- Angular
- Svelte
- Next.js
- Remix
Tooling & Request Libraries
- Storybook
- fetch
- axios
- React Query & SWR
Adoptersโ
MSW is a free library with no commercial customers, but its own README names major companies as users, and it is recommended across the testing ecosystem.
- Microsoft
- Spotify
- Amazon
- Netflix
- Recommended by Testing Library
- Frontend and full-stack JS teams
- React, Vue, and Angular projects
Adoption & Usage Statisticsโ
- 18,000+ GitHub stars
- ~18 million npm downloads per week
- ~73 million npm downloads per month
- ~195,000 repositories depend on MSW
- The de-facto standard for frontend API mocking
- Recommended by React Testing Library
Note: the named companies are stated in MSW's own README and are not independently audited, and download figures are live npm data that vary over time.
Supported Platformsโ
MSW runs in JavaScript and TypeScript across the browser, Node, and React Native, mocking REST, GraphQL, WebSocket, and SSE.
MSW runs as a library across JavaScript environments rather than as a deployed server.
- Browser
- Node.js 18+
- React Native
- TypeScript
- REST & GraphQL
- WebSocket & SSE
- Browser: all modern browsers that support the Service Worker API.
- Node.js: Node 18 or higher is required for MSW 2.x.
- React Native: supported with a dedicated integration.
- Test environments: jsdom and happy-dom under Vitest or Jest.
- Languages: JavaScript and TypeScript, with first-class TypeScript types.
- API protocols: REST, GraphQL, WebSocket, and Server-Sent Events.
Installation & Setupโ
MSW is installed as an npm dependency and registered per environment, with no server to deploy.
- Install: add the msw package as a development dependency through npm or another package manager.
- Browser: generate and register the Service Worker file, then start the worker in development or test.
- Node: set up the server listener in test setup and start it before tests run.
- Handlers: define request handlers in code and share them across environments.
- Node version: Node 18 or higher for MSW 2.x, with the legacy 1.x line for older runtimes.
- No deployment: MSW runs in-process, so there is no standalone server to host.
Architectureโ
MSW intercepts requests at the network level through a Service Worker in the browser and interceptors in Node.
- Network-level interception: requests are intercepted after they leave the application, not by patching the request library.
- Browser model: a Service Worker intercepts requests, and mocked responses appear as real network traffic.
- Node model: low-level interceptors handle requests without patching fetch or XHR.
- Handler matching: requests are matched against an ordered list of handlers, with the first match winning.
- Passthrough: unmatched requests can pass through to the real network.
- Shared definitions: the same handlers drive browser, Node, and test environments.
Request Handling & Interceptionโ
MSW handles requests through interception and matching rather than producing test-style reports.
MSW surfaces request data through console logging and lifecycle events rather than report files.
Request Outputs
MSW exposes request and interception data in the following forms.
- Console LoggingMocked requests and responses
- Lifecycle EventsHooks for custom instrumentation
- Unhandled WarningsAlerts for unmatched requests
Interception and matchingโ
- The browser uses a Service Worker and Node uses interceptors to capture requests.
- Handlers match on path parameters, wildcards, regex, query, body, and GraphQL operation name.
- Response control covers status, headers, cookies, body, delays, and network-error simulation.
- Unmatched requests use a configurable strategy of warn, error, or bypass.
Logging and eventsโ
- Mocked requests and responses are logged to the console.
- In the browser, mocked traffic appears in the DevTools Network panel.
- Lifecycle events such as request start and response mocked enable custom logging and assertions.
Observabilityโ
- Console logging: intercepted and mocked requests are logged to the console.
- Unhandled-request strategies: warn, error, or bypass handle requests with no matching handler.
- Lifecycle events: events such as request start, request unhandled, and response mocked support custom instrumentation.
- DevTools visibility: in the browser, mocked traffic appears in the Network panel.
Security & Complianceโ
- MSW is a development and test dependency that runs in your own browser or Node process, so no cloud is involved and no data leaves your environment.
- Compliance certifications such as SOC 2 or ISO 27001 are not applicable, since there is no hosted component.
- The Service Worker integration is intended for development and testing only, not production runtime mocking.
- Standard npm supply-chain considerations apply, and the MIT license keeps the source auditable.
Releases and Maintenanceโ
- Current release: MSW 2.14.6, published in May 2026, with frequent releases.
- MSW 2.0: a major rewrite in October 2023 that adopted the Fetch API standard, introduced http and graphql handlers, and set Node 18 as the minimum.
- WebSocket support: shipped in version 2.6.0 in October 2024.
- Legacy 1.x: still receives backports for older runtimes.
Pricingโ
- MSW is free and open source under the MIT license, with no paid tier, cloud, or enterprise edition.
- It is installed as an npm dependency.
- The project is funded by GitHub Sponsors.
Awards & Recognitionโ
- ThoughtWorks Technology Radar listed MSW as a solution worth pursuing in 2020 and 2021.
- MSW won an Open Source Award in 2020 for the most exciting use of technology.
- It is recommended by React Testing Library and widely treated as the standard frontend API mocking tool.
- Recognition reflects ecosystem endorsement and community adoption rather than commercial awards.
Limitationsโ
No tool is perfect, and MSW has several considerations buyers should evaluate before adoption.
- It is JavaScript and TypeScript only, so non-JavaScript stacks cannot share these mocks.
- It is in-process and client-side, not a standalone server, so it cannot act as a shared cross-team or cross-language mock backend.
- The Service Worker path is for development and testing only, not production runtime mocking.
- Node 18 or higher is required for the 2.x line, with older runtimes needing the legacy 1.x.
- There is a setup and learning curve around registering the Service Worker and the 2.0 handler API.
- Mocks live in code with no visual or no-code editor, unlike GUI tools such as Mockoon.
Best Fit Scenariosโ
- Frontend and full-stack JavaScript and TypeScript teams building React, Vue, Angular, Svelte, Next.js, Remix, or React Native apps.
- Unit and integration testing with Jest or Vitest and Testing Library.
- Component testing and Storybook stories with realistic API states.
- End-to-end browser testing with Playwright or Cypress that reuses the same mocks.
- Local development against an unfinished or unavailable backend.
- Teams that want request-library-agnostic mocking with one set of mocks shared across development and all test layers.