{bit:magie}

Jest code coverage gives no output

Solved with modified react-test script

Coverage won’t work with Jest in watch mode. Because “react-scripts test –env=jsdom” works in watch mode by default, the watch mode has to be switched off while generating the coverage output.

The following excerpt from the package.json contains a line “coverage” for illustration, how code coverage can be achieved within an app which was bootet by create-react-app.

It’s just the modified “test” script, where the options –watchAll=false and –coverage are added in combination:

 "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "coverage": "react-scripts test --env=jsdom --watchAll=false --coverage",
    "eject": "react-scripts eject"
  }