6

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!

Chen Ni
  • 979
  • 1
  • 12
  • 24
  • 4
    Can you open `.coverage/lcov-report/index.html` in the browser to check if there are uncovered lines? About how to read the coverage reporter, see https://stackoverflow.com/questions/26618243/how-do-i-read-an-istanbul-coverage-report – Lin Du Nov 29 '21 at 06:52
  • @slideshowp2 Thanks a lot! The report does show the uncovered lines! – Chen Ni Nov 29 '21 at 07:04

1 Answers1

3

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.

Chen Ni
  • 979
  • 1
  • 12
  • 24