Mock Service Worker
Intercept requests at the network layer so your app code never knows it is mocked.
What it is
MSW intercepts requests using a Service Worker in the browser and a request interceptor in Node, so the same handlers serve your unit tests, component tests, E2E tests and local development. Because the interception happens below fetch, application code needs no dependency injection or mock-aware branching.
Best for
Where it is strong
- One set of handlers reused across unit, component, E2E and local development.
- Application code is completely unaware it is being mocked — no test-only branches.
- Supports REST and GraphQL with the same model.
Where it falls short
- JavaScript ecosystem only.
- Service Worker registration adds a setup step and occasional caching confusion.
- Handlers can drift from the real API without contract verification.
Pricing
Free and open source
Open sourceFree tier: Everything, self-hosted
What drives the bill: Free and open source. You pay in engineering time and CI minutes.
Check current pricing on OSS community’s siteFigures are indicative and were last reviewed August 2026. Vendors change pricing often; confirm before you commit.
Works with
What people who use Mock Service Worker say
No reviews of Mock Service Worker yet. If you have used it in anger, yours would be the first.
Alternatives to Mock Service Worker
If Mock Service Worker is not the right fit, these solve the same problem differently.
WireMock
Test Data & Mocks
The standard HTTP mock server for JVM and beyond: record, replay, stub, simulate faults.
Mockoon
Test Data & Mocks
Spin up a realistic mock API from a desktop app in under a minute.
Prism
Test Data & Mocks
Turn an OpenAPI document into a mock server that validates as well as responds.
