使用 <Provider /> 测试 React/Redux 个组件和容器

Testing React/Redux components and containers using <Provider />

我正在编写使用 connect() wrapper/decorator 的 React 容器组件。当我使用 mochaexpect / should 进行测试时,我有兴趣为我的容器提供一个假商店。阅读文档后,我应该 export 我的组件的 flat/simple 版本,然后在测试中使用 <Provider ...>。下面是文档的 link。

https://github.com/reactjs/redux/blob/master/docs/recipes/WritingTests.md

然而,我正在努力寻找 example/guideline 来实际实施它。我知道文档可能会忽略它,因为它很明显,但我迷失了尝试连接我的测试。

我用过redux-mock-store before and using Provider around the connected component to test rendering (I used enzyme)和互动

测试 mapStateToProps:

  1. 创建具有初始状态的模拟商店
  2. 渲染组件
  3. 断言对组件的期望

测试 mapDispatchToProps:

  1. 创建具有初始状态的模拟商店
  2. 渲染组件
  3. 组件中的触发动作
  4. 对模拟商店提出期望