React · Senior · Question 62 of 75
Why mock network requests with Mock Service Worker (MSW) rather than mocking fetch in each test?
- ✓Correct answer: MSW intercepts requests at the network level, so components use their real data layer and the same handlers work in tests and dev
- 2MSW makes requests faster
- 3Mocking
fetchis impossible in Jest/Vitest
Explanation
Tests stay closer to real usage and don't break when you switch from fetch to a library. Handlers can be overridden per test for error cases.