About this project

Mock Service Worker (MSW) is an API mocking library for JavaScript that works by intercepting requests at the network level. It supports both browser and Node.js environments, allowing developers to define request handlers once and reuse them across unit, integration, and end-to-end tests, as well as local development and debugging. In the browser, MSW uses the Service Worker API to intercept outgoing requests and respond with mock definitions, keeping application code unaware of the mocking layer. In Node.js, it implements a low-level interception algorithm that works without stubbing fetch, axios, or other HTTP clients. MSW provides an Express-like routing syntax with support for parameters, wildcards, and regular expressions. Responses can include custom status codes, headers, cookies, delays, or fully custom resolvers. The library is designed to be deviation-free, meaning applications can request the same production resources and test actual behavior while mocking is active. Key features include seamless request interception, reusable mock definitions across environments, and integration with popular testing workflows. The project is widely adopted and used by companies such as Google, Microsoft, Spotify, Amazon, and Netflix.