Unit test coverage

Jest comes with built-in support for test coverage reporting. It's nice to have this included as part of your test framework because not all of them have this support. If you want to see what your test coverage looks like, simply pass the --coverage option when starting Jest as follows:

npm test -- --coverage 

When you do this, tests are run as normal. Then, the coverage tool inside Jest will figure out how well your tests cover your source, and will produce a report that looks like this:

----------|--------|----------|---------|---------|----------------|
File      |% Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|--------|----------|---------|---------|----------------|
All files |   2.17 |        0 |    6.25 |    4.55 |                |
 App.js   |    100 |      100 |     100 |     100 |                |
 index.js |      0 |        0 |       0 |       0 |  1,2,3,4,5,7,8 |
----------|--------|----------|---------|---------|----------------|

If you want to bring your coverage numbers up, take a look at the Uncovered Lines column in the report. The other columns tell you what type of code is covered by tests: statements, branches, and functions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.175.182