New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue while testing component that uses createSelector #489
Comments
I think it is because, under the hood, reselect will check the equality of your input arguments first, before checking the extracted output arguments. In Case 1 and 2, the references of the initialState passed into In Case 3 and 4, the references of the initialState are the same, therefore You won't hit such problem if you're using redux because each time you dispatch an action, a root state with a new reference will give birth under the hood. Your other observations will make sense based on the theory above. I'm poor at English. Let me know if I have made mistakes. |
I have a weird issue which is causing some of my tests to fail.
I am not sure if this is a problem with reselect or with redux-mock-store (or with me)
I created a simplified version of my problem on CodeSandbox: https://codesandbox.io/s/wizardly-wave-nkuvw?file=/src/Component.js
Here is the problem:
I have a component (Component.js) which uses createSelector to get a value from the store:
To test this component I created 2 different tests (Component.test.js) in which I use react-mock-store to mock my store.
Case 1: Mock item with ID 1 and value 1
Case 2: Mock item with ID 1 and value 2
When I create a store by calling mockStore with these items directly everything works as expected.
Case 1 returns value 1 and Case 2 returns value 2 👍
Now, in my real app I have other parts of my state that I have to mock so I start from a common object (initialState) and append these items to it. I recreated that here as Case 3 and 4:
Now Case 4 fails because the selector returns the value from Case 3 (value 1).
Some observations:
This last observation leads me to believe this might be an issue with Reselect.
I would appreciate some help. Thank you.
The text was updated successfully, but these errors were encountered: