To run the tests make sure that the node_modules are installed with yarn install
and then run yarn test
. To test an individual file yarn test src/test/file-name.js
.
Tests are run with Jest and use a behavior-driven testing style, with plain language descriptions.
describe('the thing to be tested', function() {
it('does some piece of work', function() {
expect( ... ).toEqual(...);
})
})
Assertions are written using Jest's own Library.
We use async
/await
to test asynchronous code.
The aim of all new code is to have good test coverage. A handy way to do this is to run a code coverage report. This can be done by running yarn test-coverage
. This will build the coverage report, and serve it locally. All new code can be manually scanned to see where there is no coverage. Alternately codecov.io provides a full coverage report for each PR, and the master branch.
Flow type tests are a little different, because they do not use Jest. Instead, types are created that should pass the type system. In addition, the special comment // $FlowExpectError
can be used for when errors are expected to be generated. If the types do not generate an error, then Flow will emit a warning (not an error) that something is wrong.
Test type | Description |
---|---|
components | Tests for React components, utilizing Enzyme for full behavioral testing, and snapshot tests to ensure that components output correct markup. |
store | Testing the Redux store using actions and selectors. |
types | Flow type tests. |
unit | Unit testing |