restoreHandlers()
Marks all used one-time request handlers as unused, allowing them to affect network again.
Examples
With restoreHandlers
1describe('Book detail', () => {2 before(() => {3 cy.window().then((window) => {4 const { worker, rest } = window.msw56 worker.use(7 rest.get('/book/:bookId', (req, res, ctx) => {8 return res.once(9 ctx.status(500),10 ctx.json({ message: 'Internal server error' }),11 )12 }),13 )14 })1516 cy.visit('/book/abc-123')17 })1819 afterEach(() => {20 return cy.window().then((window) => {21 const { worker } = window22 worker.restoreHandlers()23 })24 })2526 test('handles server error in the UI', () => {27 // Initial page load will trigger a one-time request handler override28 // to "GET /book/:bookId" request handler declared in the29 // `before` hook above.30 })3132 test('renders book details', () => {33 // Requests to "GET /book/:bookId" in this test will trigger a one-time request handler override34 // again, because the `.restoreHandlers()` call restore to a unused one-time request handler35 })36})