Frequently asked questions
Please see the Comparison page for detailed technical and conceptual comparison between Mock Service Worker and other popular API mocking libraries.
In a nutshell, most solutions provide requests interception on the application level, while Mock Service Worker intercepts requests on the network level. It also allows you to use the same mock definition not only for testing, but for development and debugging as well.
Yes. All request-issuing libraries are supported.
react-query, or plain
fetch—Mock Service Worker supports all libraries that issue requests in both browser and NodeJS.
Mock Service Worker provides a Node-compatible API to allow you to reuse the same mocking logic in a Node environment (for example, for testing).
Yes, but only for NodeJS integration.
Since React Native does not execute in a browser environment, you cannot run a Service Worker alongside your application.
However, you can use Mock Service Worker in your React Native project for unit and integration tests that run in Node. Please see the following page for the integration steps:
Mock Service Worker uses Service Worker API for requests interception. That API is implemented by a browser according to the Service Worker specification, making the library as secure as the worker's implementation itself.
Moreover, you are in full control over the Service Worker's code (
mockServiceWorker.js), because you copy and serve it manually.
Learn more about Service Worker security from Google.
We highly recommend committing the
mockServiceWorker.js file to Git. That way all the collaborators would have the same mocking behavior, ensuring consistent experience across the team.
Alternatively, you can generate the Service Worker file by executing
npx msw initas a part of your development pipeline.