wrap the root component in a <Provider>,or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect

Viewed 2558

I want to test component by unit test , I don't know how to render the component , it makes an error. I can use only "React-testing-library"

Error : Could not find "store" in the context of "Connect(BaseSignUp)". Either wrap the root component in a , or pass a custom React context provider to and the corresponding React context consumer to Connect(BaseSignUp) in connect options. enter image description here

1 Answers

As your component uses your Redux state, you need to wrap it with a Provider.

For example like this


  const Wrapper = ({ children }) => (
    // you could just use your normal Redux store or create one just for the test
    <Provider store={store}>{children}</Provider>
  );
  render(<BaseSignup />, { wrapper: Wrapper });
Related