redux hooks 的酶测试错误:“无法找到react-redux上下文值;请确保组件包装在 <Provider> 中”

jar*_*win 3 reactjs redux enzyme react-testing-library

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

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

这就是测试代码

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

这就是我收到的错误:

在此输入图像描述

我知道酶不支持钩子,但我不知道如何使用现在的反应测试库重构这个测试。我尝试按照消息所述使用提供者进行包装,但它不起作用,或者我做错了什么。

Mad*_*uri 5

如果您的组件包含在 Provider 服务中,您可以\xe2\x80\x99t 利用浅层渲染,因为它被应用于该服务

\n

参考 - \xe2\x80\x9cReact \xe2\x80\x94 使用浅层渲染测试 Redux 组件 \xe2\x80\x9d 作者:Scott Carmichael https://link.medium.com/wq5yEYGxQbb

\n