Mock Service Worker (MSW) intercepts HTTP at the network level for testing and development. Its vocabulary for handlers, overrides, and passthrough appears in frontend testing discussions.
0 / 5 completed
1 / 5
A developer says: 'Use MSW to mock API calls in tests instead of axios-mock-adapter.' What is MSW?
MSW (Mock Service Worker) intercepts HTTP requests at the network level using a service worker (browser) or Node.js interceptors (tests/SSR). Unlike library-specific mocks (axios interceptors, fetch mocks), MSW works regardless of the HTTP library used. You define handlers once and they work in tests, Storybook, and the browser. In discussions: 'use MSW' means mock at the network boundary rather than at the library level.
2 / 5
A developer writes: http.get('/api/users', () => HttpResponse.json([...])). What is this called in MSW?
An MSW request handler defines the interception rule: which HTTP method and URL to match, and what response to return. MSW provides http.get(), http.post(), etc. for REST and graphql.query() for GraphQL. HttpResponse.json() returns a mocked JSON response. In discussions: 'write a handler for that endpoint' means define an MSW interception rule for the API call you want to mock.
3 / 5
A developer says: 'Add a network error handler in this test to verify error state UI.' What does this mean?
In MSW, you can simulate network errors with http.get('/api/data', () => HttpResponse.error()). This is different from a 4xx/5xx response — it simulates a connection failure (like being offline). In tests, this verifies that error boundaries, retry logic, or error state UI works correctly. In discussions: 'add a network error handler' means test the sad path where the request itself fails, not just returns bad data.
4 / 5
A developer says: 'Override the handler for this one test using server.use().' What does this mean?
MSW's server.use(newHandler) adds a runtime override that takes precedence over existing handlers. Combined with server.resetHandlers() in afterEach, you can define a different response for a specific test without affecting others. This is essential for testing edge cases (empty state, pagination end, rate limiting) while keeping the default handlers for normal test scenarios.
5 / 5
A developer mentions MSW passthrough for certain endpoints. What is passthrough?
MSW passthrough lets specific requests bypass the mock handlers and go to the real network. Useful when you want to mock your own API but let third-party requests (analytics, CDN) through. In tests: http.get('https://external.api.com/*', ({ request }) => passthrough()). In discussions: 'add passthrough for the CDN requests' means don't mock those URLs — let them reach the actual server (or fail gracefully in offline test environments).