Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This is an advanced topic. Please make sure you understand React/Redux and redux-saga before proceeding.

Table of Contents

Jest

Manifold is set up with a test suite called Jest. Here is the Jest website: https://facebook.github.io/jest/. You will notice that Facebook has also written and currently maintains Jest. To avoid repetition, check out this part of the Manifold README.md: https://github.com/Picolab/Manifold/blob/master/README.md#running-tests.

...

Testing Redux Actions

Testing Redux Reducers

Testing redux-saga sagas

Redux Saga can be quite tricky to test, since it is essentially built on async actions and also because it inherently relies on javascript generators. We can approach testing a saga by looking at two different aspects; we can look at the dispatched actions that should result under certain conditions, or we could test the generator function's steps and make sure they proceed in an expected order and don't fail somewhere.

To help with looking at resulting dispatched actions, we have a developer dependency called redux-saga-tester, which simulates the redux-saga middleware and also the redux store. You can see their npm docs and our command.test.js file for examples on how to use this tool.

The test file linked to above also includes an example of how to test the saga generator function.

Enzyme

Enzyme is a utility that helps with testing React components and can be used in harmony with Jest. Here is their website: http://airbnb.io/enzyme/. Enzyme can be used for shallow rendering of components, or in other words, it is useful for testing a single component without rendering all of its child components. It has already been installed in the developer dependencies, so you shouldndon't need to npm install it.