Running snapshot tests
This guide describes how to use the test setup in the Sharetribe Web Template
Table of Contents
The Sharetribe Web Template uses the
Jest testing framework as its test runner. The
setup the template uses is based on how testing is implemented in
create-react-app. For reference, see the testing section in the
To start the test watcher that automatically updates when files change, run
If you want to run the tests once and not start the watcher, run
CI=true yarn test
Note that this also runs the linter.
Most tests included in the template are snapshot tests:
“A typical snapshot test case renders a UI component, takes a snapshot, then compares it to a reference snapshot file stored alongside the test. The test will fail if the two snapshots do not match: either the change is unexpected, or the reference snapshot needs to be updated to the new version of the UI component.”
Test files can be found next to the code they are testing and can be
identified by a
.test.js suffix. Snapshots are located in a nested
The template does not include full test coverage; the template is intended to be extended and customized which quickly renders the default tests obsolete. The default tests are there to provide a good starting point for writing tests.
in a Node environment. The test runner accesses the DOM using the
jsdom library. As the tests are run
in a Node environment, they are not exact portrayals of real browser
behaviour. This provides good iteration speed and a well-adjusted
balance between accuracy, simplicity, and performance.
Jest provides detailed documentation on their testing framework. If you are interested in extending the in-built tests provided with the templated, the following guides can provide additional insight: