Receiving stale data intermittently even after overriding endpoint and resetting handlers
See original GitHub issueEnvironment
Name | Version |
---|---|
msw | 0^0.24.2 |
node | 14.15 |
OS | Mac OS Catalina 10.15.7 |
Request handlers
I have created a new project to reproduce this issue: https://github.com/NickLewry/next-msw-swr
Current behavior
Currently I am being served the default handler response in my 2nd test even though I am overriding that response with server.use()
. Weirdly this issue has proved to be intermittent as occasionally the override will work and the tests will pass. Another strange observation is if I move the override server.use()
to the first test then I am served that response in my 2nd test even though I am calling server.resetHandlers()
after each test.
initially I thought it had to do with SWR caching the response so I implemented the cache.clear()
after each test which has not solved the issue and I also double checked the cache was empty at the beginning of the 2nd test by logging out cache.keys()
. I then also wrote a Wrapper component for <SWRConfig>
setting the dedupeInterval
to 0 as I thought requests were getting grouped but I don’t think that is the case.
This is an intermittent issue:
- If you run the tests for the first time they will pass, but as soon as you run them again immediately after (or have watch mode enabled and trigger multiple reruns by saving) you will see a failure as the wrong data is being served by the handler.
Expected behavior
I would expect the override to work in my second test by serving the updated content and for the handlers to be reset after each test.
Screenshots
N/A
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top GitHub Comments
Also @kettanaito I love this library so thanks so much for working on it 💯
It’s users like you who motivate the entire team to keep improving MSW, @NickLewry. Thank you for being a part of our journey!