valendres / playwright-msw

A Mock Service Worker API for Playwright
MIT License
162 stars 22 forks source link

Looking to know how to use resetHandlers in playwright msw #14

Closed ram5607 closed 1 year ago

valendres commented 1 year ago

Hey @ram5607, sorry for taking so long to get back to you. I have not given the library and its consumers the attention it deserves. As mentioned within the documentation, the resetHandlers function resets request handlers to the initial list given to the createWorker call. Another way to put this is that if you have added any additional mock handlers via worker.use() within a specific test, you can use resetMocks to clear those additional mock handlers. If you want to use different set of mock handlers instead of those provided to createWorkerFixture call, then these can be provided via rest parameters.

As of playwright-msw@2.0.0, I've introduced an integration test that shows how resetHandlers can be used: https://github.com/valendres/playwright-msw/blob/06011c71c2dac35e7c950fad721102b4bd5530c0/packages/example/tests/playwright/specs/rest.spec.ts#L27-L40

There are now also a lot of unit tests that should help understand how the resetHandlers function behaves: https://github.com/valendres/playwright-msw/blob/4df2fe1c0651ad925bde7744b36ccc14b3e6cafc/packages/playwright-msw/src/router.test.ts#L186-L435

If this is still unclear or you have any recommendations for what can be done to improve the documentation, please let me know!

valendres commented 1 year ago

Closing this issue due to inactivity.