Skip to content
testcritic

Mock Service Worker

Intercept requests at the network layer so your app code never knows it is mocked.

Test Data & MocksOpen sourceSelf-hostable

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

Front-end teams that want one mocking approach across every kind of test.

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 source

Free 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 site

Figures are indicative and were last reviewed August 2026. Vendors change pricing often; confirm before you commit.

Works with

JestVitestPlaywrightCypressStorybookNext.js

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.

Explore all alternatives