CodePark/ questions / External services & queues
START PRACTICINGPRACTICE
Backend question · Backend testing › External services & queues

In an MSW Node setup with server.listen() in beforeAll, what does server.resetHandlers() in afterEach do?

Removes handlers added during a test with server.use() and keeps the initial handlers passed to setupServer

It removes handlers added during a test with server.use(), and keeps the first handlers passed to setupServer. Tests use server.use(...) to override a response, for example to simulate a 500 error. resetHandlers() drops those overrides, so they don't leak into the next test.

It does not "stop intercepting requests". That is the job of
server.close() in afterAll.