CodePark/ questions / Mocking the network (MSW)
START PRACTICINGPRACTICE
Frontend question · Testing › Mocking the network (MSW)

How do you make tests fail loudly when a component calls an endpoint that has no MSW handler?

server.listen({ onUnhandledRequest: 'error' })

server.listen({ onUnhandledRequest: 'error' }) is right. onUnhandledRequest controls what MSW does with requests that no handler matches. The default is 'warn', which is easy to miss in test output. 'error' makes the problem obvious. The tempting setupServer({ strict: true }) option is wrong. It isn't an MSW API, and neither is resetHandlers('error').