Writing tests
Last updated
Last updated
In this guide, we'll walk through writing test for a custom Input
component.
HSDS uses as the testing framework and to write the actual tests.
We also have included the package to make writing tests that need simulating user events easier and more readable.
In the past we have used for testing, and a lot of tests still uses it, but do try to write your tests using the above.
Tips
Test the output of your rendered components, is your friend.
Avoid testing implementation details (internal state
for example) that enzyme tends to encourage.
All of HSDS's component test files are scoped in the same directory as the component, example:
In our Input.test.js
file, we'll need to add:
For test development, open up your terminal and run the following command:
This fires up Jest in watch mode, and runs tests against modified files (and their associated files).
To check code coverage, run the following command:
You can open the index.html
in your browser to view the full report.
We strive to have as much coverage as posible, and for that purpose we set the threshold at 95% coverage.
Why not 100%? 100% coverage is a false metric and it does not indicate whether your component is properly tested, and while we maintained 100% coverage for a long period we noticed an excessive usage of istanbul ignore
directives, this wasn't because of lazyness but because some things are close to impossible to test in the Jest/JSDOM environment or because istanbul
couldn't reach the code for some reason.
This runs through the entire Jest test suite, and generates a under:
Let's to make sure other folks know how to use Strong
.