Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactJS: Jest coverage report of untested files shows 0% coverage

I tried testing code coverage of untested source js files of my React application using jest but was shocked to see that it mostly gave 0% code coverage for all files. Is it fine to test code coverage of component.js files of React using Jest or am I doing anything incorrect here.

Here is my jest configuration specified in package.json:

  "jest": {
    "testEnvironment": "node",
    "collectCoverageFrom" : ["**/src/**/*.js"]
  }

my coverage snapshot:

coverage report

I don't believe that 0% of my code statements are executing for all files. Any thing I am missing here? Is this report fine for es6 app? I even tested the code coverage of react boilerplate app created using react cli create-react-app by ejecting webpack. Even the boilerplate app shows code coverage as 0% for untested js files. This is 100% false. Any idea on this results?

like image 972
Peter Avatar asked Nov 08 '22 18:11

Peter


1 Answers

Note, that collectCoverageFrom need provide with collectCoverage as Jest docs told us:

This option requires collectCoverage to be set to true or Jest to be invoked with --coverage

like image 185
storenth Avatar answered Nov 15 '22 05:11

storenth