Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using v8 as the coverageProvider, used files without tests are being reported with 100% coverage #543

Open
pasanenf opened this issue May 25, 2023 · 2 comments

Comments

@pasanenf
Copy link

pasanenf commented May 25, 2023

I am experiencing the same issue as #422 with some Vue files not included in the coverage report, so I decided to try changing to v8 as recommended. However, using v8, used files without tests are being reported as having 100% coverage.

In the repo below, there are tests for two components, RedirectLink and Anchor. There is another component (ArrowLink) that is not used, and it is being correctly reported with 0% coverage.

Repo: https://github.com/pasanenf/jest-coverage-bug


RedirectLink is using Anchor to display links, and Anchor is being stubbed in the tests. The stub is not the Anchor component mentioned above, but another one under __mocks__. (Even if Anchor is not stubbed, coverage is the same.)

shallowMount(RedirectLink, {
  global: { stubs: { Anchor } },
  ...
});

Anchor has also got tests, but it is only using standard HTML. There are a few branches and functions in the code, so I'd expect these to be counted in the report, even if I'm not actually testing Anchor.

When testing only the RedirectLink component, the Anchor component is reported with 100% coverage.

$ yarn test __tests__/components/RedirectLink.test.js

------------------|---------|----------|---------|---------|-------------------
File              | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
------------------|---------|----------|---------|---------|-------------------
All files         |   69.86 |        0 |       0 |   69.86 |
 Anchor.vue       |     100 |      100 |     100 |     100 |
 ArrowLink.vue    |       0 |        0 |       0 |       0 | 1-21
 RedirectLink.vue |      96 |      100 |       0 |      96 | 23
------------------|---------|----------|---------|---------|-------------------

However, test everything, and the coverage changes.

$ yarn test

------------------|---------|----------|---------|---------|-------------------
File              | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
------------------|---------|----------|---------|---------|-------------------
All files         |   68.49 |    33.33 |       0 |   68.49 |
 Anchor.vue       |   96.29 |       50 |       0 |   96.29 | 25
 ArrowLink.vue    |       0 |        0 |       0 |       0 | 1-21
 RedirectLink.vue |      96 |      100 |       0 |      96 | 23
------------------|---------|----------|---------|---------|-------------------

Is this the expected behavior? I'd expect the coverage for Anchor to be the same, even if I'm not specifically testing Anchor. Btw, removing the tests for Anchor and running yarn test also results in 100% coverage for Anchor.

@steele-cjf
Copy link

yeah,same question,has any solution?

@michaelsimmonds
Copy link

michaelsimmonds commented Jan 8, 2024

Running into this issue too. Coverage seems to default to 100% when components which use <script setup> that don't have their own tests run are imported into a file which is being tested. If their own tests are run then coverage is calculated properly.

If you change the component to not use <script setup> then it doesn't default to 100% but this is not really a viable solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants