how to remove snapshot's consideration from coverage report generation in jest
Asked Answered
B

2

10

See the demo app by doing npm run test:2 https://github.com/adamchenwei/jest-playground.git

You will see the App.js is 100% covered, and it only really has a snapshot.

Are there ways we can tell Jest to ignore snapshot as coverage evidence? Or its what expected?

I haven't been able to find any answers online or even questions been asked, I suspect its either I am asking the wrong question or people consider 100% coverage snapshot as normal, while I feel its render coverage report meaningless in a sense that it only test the template matching from the previous component.

Brownlee answered 21/11, 2017 at 15:23 Comment(2)
I would love this as a feature. Snapshots are bad for coveragePang
Hi man, after all these years, have you found a way? For me, snapshots are just a fallback check, and I don't want it to affect coverage and affect team members to do real unit tests.Lamothe
B
1
"jest": {
    "coveragePathIgnorePatterns": [
        ".*__snapshots__/.*"
    ],
    ...
},
Bellicose answered 8/3, 2022 at 13:6 Comment(0)
U
-3

It's pretty easy, you need to remove the --coverage flag and set collectCoverage inside your package.json. This issue seem to occur just with the CLI flag and not within the configuration way which is already reported by #6859. Look at the following configuration:

{
    // ...
    "collectCoverage": true,
    "collectCoverageFrom": ["**/*.tsx?"],
    // ...
}
Unclassical answered 3/10, 2018 at 12:2 Comment(1)
this settings doesn't ignore the snapshot tests. The question was how not to consider snapshots when generating the tests as a snapshot can increase the test coverage but it doesn't test anything and it doesn't make sure your code works.Isolate

© 2022 - 2024 — McMap. All rights reserved.