Out of the box test coverage is not 100%
See original GitHub issueI love this as a starting point for React apps, but I am puzzled by one thing…Having Jest and test coverage built in is awesome, but why isn’t coverage 100% out of the box?
If I run the test coverage report, I see:
[Thu Jan 12 11:29:25] fb $ npm test -- --coverage
> fb@0.1.0 test /Users/rob/repos/fb
> react-scripts test --env=jsdom "--coverage"
PASS src/App.test.js
✓ renders without crashing (18ms)
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | 50 | 100 | 100 | 50 | |
App.js | 100 | 100 | 100 | 100 | |
index.js | 0 | 100 | 100 | 0 | 1 |
----------|----------|----------|----------|----------|----------------|
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 1.137s
Ran all test suites.
It’d be great to start folks off with 100% tested code - no matter how trivial the index.js file is =)
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
How can 100% test coverage be "not enough to prove working ...
100 % coverage does not mean it meets user expectations - Your tests could cover 100% of the code, but that does not...
Read more >Create React App - Out of the box coverage is not 100%
A simple solution could be to exclude the index.js file from tests by adding the following code to the package.json file.
Read more >Test Coverage in Software Testing (Tips to Maximize Testing ...
When only 90 tests relating to 8 requirements have assigned testers and the rest of them are not, we say the test assignment...
Read more >The test coverage trap - Arnold Galovics
How much test coverage is acceptable? Some people immedately say 100%, some say 90% and it ultimately stops at like 50%.
Read more >Should You Aim for 100 Percent Test Coverage? - NDepend
Many in the debate — particularly those on the “less is more” side of it — quickly point out that test coverage does...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@TheRobBrennan -
You can exclude index.js from coverage reporting.
I remedied the problem by adding Note: this worked for me on the ejected version of create-react-app. Can’t say for sure how this would behave otherwise
"jest": { "coveragePathIgnorePatterns": ["<rootDir>/src/index.js"] }
https://facebook.github.io/jest/docs/configuration.html#coveragepathignorepatterns-array-string
I’m experiencing the same issue. I can’t tell if these Jest configs work on an unejected app at all.
edit: However I did have luck adjusting the CLI script. Adding this flag worked for me
--collectCoverageFrom='["src/**/*.{js,jsx}", "!src/index.js"]'