1

Can someone compare and contrast SinonJS to Mock Service Worker MSW? Something similar to https://mswjs.io/docs/comparison

1 Answers1

1

Sinon is a general-purpose stubbing library for JavaScript. It allows you to stub (replace) various things: modules, functions, anything.

MSW specializes in API mocking and does not stub anything internally. Both in the browser and in Node.js, your request client (the code that does the actual request) gets executed, the requests get performed. They are then intercepted and responded with mocked data. This gives you much more confidence for testing and development simply because you're removing fewer parts of your application (stubbing === removing and replacing).

I can recommend Sinon for stubbing a module your application depends on during tests (although jest.mock is a good alternative). I would recommend MSW whenever you need to mock an API call.

Christos Lytras
  • 36,310
  • 4
  • 80
  • 113
kettanaito
  • 974
  • 5
  • 12