`server.use()` or `server.resetHandlers` do not appear to be working within/between tests
See original GitHub issueDescribe the bug
server.use()
or server.resetHandlers
do not appear to be working within tests.
I have a setupTests
file that is appropriately calling resetHandlers
(confirmed with logging) after each test.
When using a server.use
statement to override a route payload like so:
server.use(
rest.get('myUrl', (req, res, ctx) => {
return res(ctx.json([]));
})
);
I would expect the result to return as an empty array. My main handlers file is setup similarly:
rest.get('myUrl', (req, res, ctx) => {
return res(ctx.json(mockDataArray));
})
When running all my tests, I see my mock data, and can log it to the console in the actual component implementation.
When running as part of a test suite, I do not get the overridden empty array that I want, I see the original list from the handlers.
The bug I think I’ve found is that if I run the test as it.only
then I see the correct empty array and my test passes. My component logs out the empty array as the fetched data I was expecting. Running the tests completely by itself seems to fix the issue.
I’m hoping this is just a silly mistake on my part.
Environment
msw: 0.19.5
nodejs: 12.16.1
npm: 6.13.4
Please also provide your browser version. n/a
To Reproduce
Steps to reproduce the behavior: I attempted to reproduce this behavior using the react example project, but haven’t been able to yet.
Expected behavior
I have a setupTests
file that is appropriately calling resetHandlers
(confirmed with logging) after each test. When using server.use
to setup a route override, I should get the payload assigned (as one would expect from the docs as well as the example project.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:27 (9 by maintainers)
Top GitHub Comments
For anyone coming to this who is using react-query. You will need to add
I have tried as above and it works. Let me know if I’m wrong