0
votes

I am full rendering a component using mount like this:

const wrapper = mount(<Component />);

And this component renders a child component which uses React-Redux. I want to provide the Redux mock store to only the child component. How do I do it?

1
What's your case? Why is providing it to Component a problem? There's no good way to do this, and the problem is likely in a way you test it.Estus Flask
@estus Component do not use Reduxuser117829
Then applying <Provider> to it won't create problems. You're applying at the top of component hierarchy in production app, not to every component. This is primarily Enzyme question, isn't it? shallow belongs to Enzyme, not Jest.Estus Flask

1 Answers

0
votes

A store should be provided to whole component hierarchy:

mount(<Provider store={mockStore}><Component /></Provider>)

This should create no problems if testing strategy was chosen properly. In case parent and child components need different conditions to be tested, this likely means that they should be tested in isolation with shallow instead of mount.