Skip to content

Jest Test Coverage

Harry Turnbull edited this page May 28, 2020 · 1 revision

Jest Test Coverage Configuration

In jest.config.json:

{
  "setupFiles": [
    "<rootDir>/src/setupTests.js"
  ],
  "testRegex": "/*.test.js$",
  "collectCoverage": true,
  "coverageReporters": [
    "lcov"
  ],
  "coverageDirectory": "test-coverage",
  "coverageThreshold": {
    "global": {
      "branches": 0,
      "functions": 0,
      "lines": 0,
      "statements": 0
    }
  },
  "moduleDirectories": [
    "node_modules",
    "src"
  ]
}

To get coverage report:

npm run test -- --coverage --watchAll=false

Clone this wiki locally