Skip to content

Coverage Below Threshold

Error message

                Jest: Coverage threshold not met — branches: 75% < 80%
              

Quick summary

Your test suite passes, but coverage is below the configured threshold. New code was added without sufficient tests.

Why this happens

  • New code was added without corresponding tests.

  • Existing tests were removed or skipped.

  • New branches (if/else) were added without testing all paths.

  • The coverage threshold was set too high for the current codebase.

Minimal example

✗ Broken code
// New function added without tests
function newFeature(x) {
  if (x > 0) return 'positive';
  return 'non-positive';
} // Coverage drops below threshold
✓ Fixed code
// Add tests for the new function
test('newFeature returns positive for positive input', () => {
  expect(newFeature(5)).toBe('positive');
});
test('newFeature returns non-positive for zero/negative', () => {
  expect(newFeature(0)).toBe('non-positive');
  expect(newFeature(-1)).toBe('non-positive');
});

Add tests covering both branches of the new function to meet coverage threshold.

How to diagnose

  • Run jest --coverage to see the coverage report and identify uncovered code.

  • Look for files with low coverage percentages.

  • Check if new code was recently added without tests.

  • Review which branches or lines are uncovered.

How to fix

  • Write tests for the uncovered code — focus on meaningful tests, not just coverage.

  • If the threshold is unrealistic, lower it in the Jest configuration.

  • If the uncovered code is unreachable or not worth testing, add a /* istanbul ignore */ comment.

How to prevent

  • Write tests alongside new code (or before, with TDD).

  • Set realistic coverage thresholds — 80% is a common starting point.

  • Run coverage locally before pushing to CI.

Related Resources

Related Lessons

← Back to language