Jest "coverage threshold ... not met" - Fails the Build in CI
All tests passed but Jest exited non-zero because measured coverage fell below a configured coverageThreshold. New untested code, or files that were not collected, dragged a metric under the bar.
What this error means
The run prints the coverage table, then "Jest: \"global\" coverage threshold for lines (80%) not met: 76.4%" and fails the job even though every test is green.
Jest: "global" coverage threshold for lines (80%) not met: 76.42%
Jest: "global" coverage threshold for branches (75%) not met: 71.1%Common causes
New code added without tests
Recently added lines or branches are untested, pulling the percentage below the configured threshold.
Files not included in collection
Without collectCoverageFrom, only imported files are counted; entirely untested files are invisible, then suddenly counted once imported, dropping the average.
How to fix it
Add tests for the uncovered lines
Open the HTML/text report to see exactly which lines and branches are missing, and cover them.
jest --coverage
# open coverage/lcov-report/index.html to find red linesSet thresholds and collection explicitly
// jest.config.js
module.exports = {
collectCoverageFrom: ['src/**/*.{ts,tsx}', '!src/**/*.d.ts'],
coverageThreshold: { global: { lines: 80, branches: 75 } },
};How to prevent it
- Define
collectCoverageFromso all source is measured consistently. - Add tests with new code so coverage never regresses below the bar.
- Ratchet thresholds up over time rather than down.