Question · JavaScript and React course · Module 13: Testing React

MSW vs mocking fetch

What is the main advantage of MSW (Mock Service Worker) compared with mocking fetch?

Answer options

  • MSW generates the API schema automatically
  • MSW needs less setup code than jest.mock
  • MSW intercepts requests at the network level, so the test is more realistic
  • MSW only works in the browser, not in Node.js

You can check the correct answer by solving this task in the CodeWorlds game.