## TL;DR

A refactor changed the code-to-test ratio, and the threshold is now wrong or a real gap appeared. Check which lines are uncovered: if they are dead code, delete them; if they are real logic, add tests; only then adjust the threshold.

## Error

```text
ERROR: Coverage thresholds not met: lines 82% (threshold 90%), branches 75% (threshold 85%)
```

## Steps

1. Open the HTML coverage report and find the uncovered lines. Expected: a concrete list, not a percentage.
2. If the uncovered code is dead (leftover from the refactor), delete it. Expected: coverage rises without new tests.
3. If it is real logic, write tests for it before touching the threshold. Expected: the gap is genuinely covered.
4. Only if the threshold itself is stale (for example it counted generated code), update it in config with a comment explaining why. Expected: a justified number, not a lowered bar.
5. Re-run coverage. Expected: green with the code honestly covered.

## When to use

- Coverage gates fail after a refactor.
- You need to decide between more tests and a threshold change.

## When not to use

- First-time coverage setup (different task).
- You want to lower thresholds to make CI green (that deletes the gate's value).

## Tool compatibility

- Vitest 0.30 through latest; v8 or istanbul provider.

## Variant phrasings

### Coverage threshold failed in Vitest

The general failure; inspect the report before acting.

### Lines below threshold after refactor

Usually dead code from the refactor; delete first.

## Why it happens

Refactors move, delete, and add code. Thresholds are absolute numbers against a moving codebase, so they drift out of sync.

## Edge cases

- Generated code (GraphQL types, mocks) should be excluded from coverage, not covered.
- Branch coverage is stricter than line coverage; a refactor adding branches needs branch tests.
- 100% thresholds make every refactor a coverage chore; 80-90% with review is saner.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_ViKlNvxBWq_Sbikm6dclWg
