5
votes

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?

1

1 Answers

1
votes

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