redux 挂钩的酶测试错误:"could not find react-redux context value; please ensure the component is wrapped in a <Provider>"

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

我正在重构项目中的一些代码,将 class 组件传递给功能组件。在我的测试中出现了一些错误。

我有一个名为“MenuWeb”的组件,我现在正在使用 redux hooks。

这是测试代码

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

这就是我遇到的错误:

我知道酶不支持挂钩,但我不知道如何使用 now React 测试库重构此测试。我尝试按照消息中的说明使用提供程序进行包装,但它没有用,或者我做错了什么。

如果您的组件包装在 Provider 服务中,您将无法利用浅层渲染,因为它被应用于此

参考 - “React — 使用浅层渲染测试 Redux 组件”,作者 Scott Carmichael https://link.medium.com/wq5yEYGxQbb