Open followynne opened 9 months ago
Thanks for filing and the repro! I'll try to look at it when I get a chance, but I'm on travel and it may be a while.
No worries, thanks for checking in already! We're not in an hurry to update and can wait when you have some free time 😁
for what it's worth, if you add enhancers: (getDefaultEnhancers) => getDefaultEnhancers({ autoBatch: false })
to your store setup, the tests pass again.
The autoBatchEnhancer
is added to the store by default in RTK 2.0, and your test seems to function in such a way that it doesn't account for this batching of subscribers.
So probably adding another await Promise.resolve()
before making the assertions might already make it pass without disabling the autoBatching behaviour (which you should probably keep on).
@EskiMojo14 @phryneas
thanks a lot for the answer! I gave a try to both suggestions and I can confirm that
Hello everyone,
in our project we use Vitest as the test runner and MSW to mock endpoint calls.
Issue
When I upgrade react-redux: 8.1.3 => 9.0.4 and RTK: 1.9.7 => 2.0.1, some tests start to fail.
We have a selector that access an RTK Query in the following way:
In the real application we call the getUser endpoint before rendering the React application and it works fine when we upgrade the versions.
During testing we execute the api call manually and mock it out with MSW; with the v8/v1 versions the selector updates correctly while, on the latter versions, the selector doesn't change after the first render.
Steps to reproduce
I created this CodeSandbox sample with the minimum amount of code to reproduce the issue.
If you run the test terminal with the sandbox as-it-is, you'll see the successful tests; if you upgrade the versions the tests will fail (you'll see in the logging the different behavior).
Additional info
If it's not a bug, can you kindly point us to a different approach to get the API results in a selector function?
Thanks for the help 🤗