question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Out of the box test coverage is not 100%

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
wasifhydercommented, Apr 10, 2017

@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

5reactions
thecristencommented, Apr 10, 2017

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"]'

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found