-
-
Couldn't load subscription status.
- Fork 1.2k
Description
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:
const selectUserResult = userApi.endpoints.getUser.select();
export const selectUser = createSelector(
selectUserResult,
(userResult) =>
userResult.data ?? { Id: "", Email: "", Permissions: [] as Array<string> },
);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 🤗