Unit tests are run using ts-jest, which is basically a TypeScript loader for Jest.
Tests are by default executed for all packages at once. Simply run the following command in the root directory:
yarn test
We're using React Hooks Testing Library for testing hooks as it allows us to abstract from any component and focus on the hook directly. The library integrates seamlessly with Jest, therefore there's no need for any special treatment when running the tests.
To run tests within the WebStorm IDE, you have to make it read the Jest settings from the root package.json
because by default it looks into a package.json
that is closest to the spec file.
- Open the
Run / Debug Configurations
dialog - Expand the
Templates
section - Select the
Jest
template - Set the
Working directory:
field to the root folder of the project - Save the template by clicking the
OK
button
These steps will make Jest start in the root folder regardless of in which package you initiate the test.
Jest will then pick the config from the root package.json
.