1
votes

I am updating a unit test in jest and enzyme on a React component and running into an issue.

I recently added a child component (that itself is connected to Redux) to the parent component that is using enzyme's ‘mount’ and the unit test has failed.

Note the project compiles and works fine.

This is the error given on the CLI:

Invariant Violation: Could not find "store" in the context of "Connect("ChildComponent Name Here")". Either wrap the root component in a , or pass a custom React context provider to and the corresponding React context consumer to Connect("ChildComponent Name Here") in connect options.

I have confirmed that the Redux connected child component is causing the issue.

Is it possible to mock the store of a child component in this instance?

1
Can you please provide the test case code so that we can help you better?Harshit Agarwal

1 Answers

0
votes

This happens when you link your component to redux store and you use mapStateToProps function of react-redux. So when you mount the component you need to wrap it inside Provider to provide the store context to your component. You can do something like this:

let wrapper = mount(<Provider store={store}><Component /></Provider>);

Hope this helps!