ts-jest "Cannot find name 'describe'" - Missing Jest Types
TypeScript could not find the globals describe, it, and expect because the Jest type definitions are not loaded. Either @types/jest is missing, or tsconfig restricts types and excludes it.
What this error means
Compilation fails with "Cannot find name 'describe'." (and the same for it/expect/beforeEach). It typically appears after enabling types in tsconfig or when @types/jest was not installed in CI.
src/cart.test.ts:3:1 - error TS2304: Cannot find name 'describe'.
3 describe('cart', () => {
~~~~~~~~Diagnose it: flake, environment, or genuine failure?
Before debugging the assertion, establish whether the test is deterministic. A test that fails only in CI is usually order-dependent, time-dependent, or racing something, and fixing the assertion will not help.
# does it fail in isolation?
npx vitest run path/to/file.test.ts
# is it order dependent? run the suite in a random order twice
npx vitest run --sequence.shuffle
# is it a race? run the same file repeatedly
for i in $(seq 1 20); do npx vitest run path/to/file.test.ts || break; doneCommon causes
@types/jest not installed
The Jest global type definitions are not in node_modules, so TypeScript has no declaration for describe/it/expect.
tsconfig "types" excludes jest
Setting compilerOptions.types restricts which @types packages load. If jest is not in the list, its globals are not in scope even when installed.
How to fix it
Install the Jest type definitions
npm install -D @types/jest
# (or use Vitest globals / @jest/globals imports instead)Include jest in tsconfig types
// tsconfig.json
{
"compilerOptions": {
"types": ["jest", "node"]
}
}CI-only causes worth ruling out
- Runners have fewer cores than a laptop, so timing-sensitive tests that pass locally fail under contention.
- No TTY and a different locale or timezone. Snapshot tests containing formatted dates or numbers are the usual casualty; pin
TZandLANGin the job. - Parallel workers sharing a database, a port, or a temp directory. Give each worker its own namespace.
- Default timeouts calibrated on a fast machine. A cold runner is slower on first execution, especially before any cache warms.
How to prevent it
- Keep
@types/jestin devDependencies and the lockfile. - If you set
typesin tsconfig, includejestexplicitly. - Run
tsc --noEmitin CI so type errors surface before tests.