Enzyme test error with redux hooks: "could not find react-redux context value; please ensure the component is wrapped in a <Provider>"

Viewed 5635

I'm refactoring some code in my project passing the class component to funcional component. And got some error in my test.

I have a component called "MenuWeb" where I'm using now redux hooks.

That's the test code

describe('Testing MenuWeb', () => {
  it('should render Menu Web correctly', () => {
    const wrapper = shallow(<MenuWeb store={store} />)
    expect(wrapper).toMatchSnapshot()
  })

And that's the error that i'm getting:

enter image description here

I know that enzyme don't support hooks, but i don't know how to refactor this test using now react testing library. I tried to wrap with a provider as the message says, but it didnt work, or i'm doing something wrong.

1 Answers

If your component is wrapped in the Provider service you can’t take advantage of shallow rendering due to it being applied to that instead

Reference - “React — Testing Redux Components with Shallow Rendering” by Scott Carmichael https://link.medium.com/wq5yEYGxQbb

Related