'Meaning of function coverage in Jest
Here is the output from running jest on one of my components:
----------------------------|---------|----------|---------|---------|-------------------
File | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
----------------------------|---------|----------|---------|---------|-------------------
All files | 100 | 100 | 50 | 100 |
search-suggestion-base.tsx | 100 | 100 | 50 | 100 |
----------------------------|---------|----------|---------|---------|-------------------
...
Jest: "global" coverage threshold for functions (100%) not met: 50%
Note that % Funcs is not 100 and the test fails. (The coverage threshold is not set by me. I wouldn't have set such a high threshold.)
The problem is, Jest is not telling me which are the uncovered lines. Besides, I'm also having trouble figuring out what's the meaning of % Funcs. I can't even find the official documentation for this % Funcs.
Any help is appreciated!
Solution 1:[1]
As pointed out by @slideshowp2, .coverage/lcov-report/index.html does show the uncovered lines.
The .coverage folder didn't exist at fist. I had to ran jest with the --coverage parameter. You can refer to How to get the code coverage report using Jest? for more information.
By the way, it turned out that a default event handler - which is a function - was not covered. So I guess % Funcs means literally the percentage of functions covered.
In my case, the default event handler is an empty function () => {}. I think that's why Jest told me that "statements, branches and lines" are all covered, but "functions" are not.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Chen Ni |
