React · Senior · Question 62 of 75

Why mock network requests with Mock Service Worker (MSW) rather than mocking fetch in each test?

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.

Further reading

Problem with a question

React · Senior · question 62

Test yourself

Take the React · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz