我们使用 Enzyme 和 Jest 进行测试。在我们的代码库中更新到最新版本的 react-redux,并且所有连接的组件测试用例开始失败(版本 6)。使用
import { createMockStore } from 'redux-test-utils';
创建商店
适用于旧版本的测试用例:
const wrapper = shallow(<SomeConnectedComponent />, {context: { store }});
这失败给出错误
不变违规:在“Connect(SomeConnectedComponent)”的上下文中找不到“store”。
阅读了几篇文章,得到了使用提供程序包装器安装和包装的建议
const wrapper = mount(<Provider store={store}><SomeConnectedComponent /></Provider>);
上面的代码有效,但我希望它与吞咽一起用于单元测试。
编辑 :
const wrapper = shallow(<Provider store={store}>
<SomeConnectedComponent />
</Provider>)
上面的代码返回空的shallowWraper 对象。
使用 react-redux 版本 > 6 吞下连接组件的最佳方法是什么