7

I am trying coverage feature on jest tests but output shows 100% coverage for files which are referenced by tests, but not covered at all.. mostly they are just dependencies of modules which are tested and I am far from using all exported methods from them. Any idea why I am getting this phantom coverage? Thanks for any hint

--------------------------------------|----------|----------|----------|----------|-------------------|
File                                  |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
--------------------------------------|----------|----------|----------|----------|-------------------|
All files                             |     6.93 |     5.48 |     3.22 |     7.18 |                   |
 src                                  |    10.11 |    10.53 |     5.88 |    10.11 |                   |
  const.ts                            |      100 |      100 |      100 |      100 |                   |
  utilities.ts                        |      100 |      100 |      100 |      100 |                   |
... etc

utilities.ts have meny exported methods but no one is tested yet and are counted as 100% covered :/

I did not google out any similar case. Most of people ask why their test coverage isnt 100% :D

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Luckylooke
  • 4,061
  • 4
  • 36
  • 49
  • 2
    Did you ever get to the bottom of it? I am having the same issue .... – Balkyto Jul 07 '21 at 15:21
  • 1
    @Balkyto I think it was fixed once I set ` collectCoverageFrom: ['/src/**/*.(ts|vue)'], coveragePathIgnorePatterns: ['/node_modules/', '/src/services/mocks/'], ` in jest.config.js – Luckylooke Jul 07 '21 at 18:58
  • I suppose there are also similar options for CLI ;) – Luckylooke Jul 07 '21 at 18:59
  • I tried that, and that "kinda works", but I have a feeling Jest is generous with percentages there. As soon as method is once invoked in test, it seems that it's "100% covered", even if it's doing nothing. But that's the other problem... maybe I'm expecting too much of it. – Balkyto Jul 09 '21 at 12:17
  • I'm having this very same issue: my coverage results is 100%, even for files without tests. @Luckylooke, would you mind adding your jest.config file to the question? – darksoulsong Feb 17 '22 at 19:21
  • Can you solved this issue or any updated ? – Loga Thrim Feb 13 '23 at 04:42
  • meanwhile I have moved to vue3 + vitest, there is no problem with this, but I can try to post jest.config.js later – Luckylooke Feb 14 '23 at 10:59

0 Answers0