Frederik, thanks for the article - really helped me testing certain component in our app!
For those who are stumble upon it and need to test components with multiple useSelector's, do as article suggests, and add this:
//Mock your selectorsjest.mock('path/to/selectors',()=>{constActualHelpers=jest.requireActual('path/to/selectors');return{...ActualHelpers,selectorNumberOne:jest.fn(),selectorNumberTwo:jest.fn(),};});//and then inside of your it()/test():selectorNumberOne.mockReturnValue('value you need')selectorNumberTwo.mockReturnValue('value for selector #2')// and so on
Thanks, Fredrick for the article and Sergey for that comment.
I have a slightly different setup: I've wrapped RTL render with my redux-dynamic-modules provider, so I think there's no need to mock react-redux or useSelector, and all I need to actually mock is the return value of my selector function.
I'm trying to implement it the way shown in your comment, but I'm getting an error that my selector is undefined.
Frederik, thanks for the article - really helped me testing certain component in our app!
For those who are stumble upon it and need to test components with multiple
useSelector's, do as article suggests, and add this:Thanks, Fredrick for the article and Sergey for that comment.
I have a slightly different setup: I've wrapped RTL render with my
redux-dynamic-modulesprovider, so I think there's no need to mockreact-reduxoruseSelector, and all I need to actually mock is the return value of my selector function.I'm trying to implement it the way shown in your comment, but I'm getting an error that my selector is
undefined.Paste your code here
And I get
Cannot destructure property 'users' of 'react_redux_1.useSelector(...)' as it is undefined.error from component