Skip to content

Jest Coverage Report Not Generating Fix

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about Jest Coverage Report Not Generating Fix. We cover key concepts, practical examples, and best practices.

Running jest doesn't produce a coverage report — no output files, no HTML report, and the terminal doesn't show coverage percentages.

The Problem

# WRONG — missing --coverage flag
jest
PASS  src/utils/helper.test.js
PASS  src/services/api.test.js

Tests:    12 passed, 12 total
# No coverage information shown

Without the --coverage flag, Jest runs tests but doesn't instrument code or generate coverage data.

Step-by-Step Fix

1. Enable coverage collection

# RIGHT — run with coverage
npx jest --coverage
// OR — enable in config
module.exports = {
  collectCoverage: true,
  collectCoverageFrom: ['src/**/*.{js,ts}'],
};

2. Configure coverage reporters

// RIGHT — multiple coverage reporters
module.exports = {
  coverageReporters: [
    'html',    // Generates coverage/ directory with HTML report
    'lcov',    // Generates lcov.info for CI tools
    'text',    // Prints summary to console
    'text-summary', // Brief text output
    'json',    // Machine-readable JSON
    'clover',  // CI integration format
  ],
};

3. Set output directory

// RIGHT — custom output directory
module.exports = {
  coverageDirectory: '<rootDir>/coverage',
};

// Or use in CLI:
// npx jest --coverage --coverageDirectory=reports/coverage

4. View the report

# Generate coverage
npx jest --coverage

# Open HTML report
open coverage/lcov-report/index.html
# Or on Linux:
xdg-open coverage/lcov-report/index.html

Expected output:

File                  | % Stmts | % Branch | % Funcs | % Lines
----------------------|---------|----------|---------|---------
All files             |    87.5 |    81.25 |    91.6 |    87.5
 src/utils/helper.js  |     100 |      100 |     100 |     100
 src/services/api.js  |      75 |     62.5 |   83.33 |      75

Prevention Tips

  • Add --coverage to your CI test script
  • Configure coverageReporters for your preferred formats
  • Use coverageDirectory to organize output
  • Generate HTML reports for local review
  • Use lcov for CI pipeline integration

Common Mistakes with coverage report

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. Mixing let bindings with <- bindings in do notation, producing type errors

These mistakes appear frequently in real-world JEST code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### Why is my coverage report empty?

Make sure collectCoverageFrom includes your source files. If it's not set, Jest only collects coverage from files that are imported in tests. Explicitly specify glob patterns to include all source files.

What's the best coverage reporter for CI?

Use lcov for CI — it generates lcov.info that integrates with services like Codecov, Coveralls, and SonarQube. Add text or text-summary for console output in CI logs.

How do I exclude coverage from specific directories?

Use coveragePathIgnorePatterns in Jest config or ! negation patterns in collectCoverageFrom. Common exclusions: node_modules, test files, configuration files, and type declarations.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro