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

Viewed 1246

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.

2 Answers
"jest": {
    "coveragePathIgnorePatterns": [
        ".*__snapshots__/.*"
    ],
    ...
},

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?"],
    // ...
}
Related