Skip to content
Latchkey

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.

ts-jest
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.

Terminal
# 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; done

Common 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

Terminal
npm install -D @types/jest
# (or use Vitest globals / @jest/globals imports instead)

Include jest in tsconfig types

tsconfig.json
// 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 TZ and LANG in 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/jest in devDependencies and the lockfile.
  • If you set types in tsconfig, include jest explicitly.
  • Run tsc --noEmit in CI so type errors surface before tests.

Frequently asked questions

What causes ts-jest "Cannot find name 'describe'"?
There are 2 common causes: @types/jest not installed and tsconfig "types" excludes jest. The Jest global type definitions are not in node_modules, so TypeScript has no declaration for describe/it/expect.
How do I fix ts-jest "Cannot find name 'describe'"?
There are 2 fixes depending on which cause you have: install the jest type definitions and include jest in tsconfig types. Work through them in order, since the first is the most common.
What does ts-jest "Cannot find name 'describe'" actually mean?
Compilation fails with "Cannot find name 'describe'." (and the same for it/expect/beforeEach).
How do I stop ts-jest "Cannot find name 'describe'" happening again?
Keep @types/jest in devDependencies and the lockfile. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card