Skip to content
Latchkey

Vitest "Test timed out in 5000ms" (testTimeout) in CI

Vitest fails a test that does not finish within testTimeout (5000ms by default). In CI, slower runners or a promise that never resolves push tests over the limit. Raise the timeout for genuinely slow work, or fix the unresolved async.

What this error means

A test fails with "Test timed out in 5000ms. If this is a long-running test, pass a timeout value as the last argument." more often on CI than locally.

Vitest
Error: Test timed out in 5000ms.
If this is a long-running test, pass a timeout value as the last argument.
 ❯ src/fetch.test.ts:14:3

Common causes

A promise that never resolves

An awaited call hangs (an unmocked network request, an unfired fake timer), so the test cannot complete before the timeout.

A genuinely slow test on a slower runner

CI runners can be slower than a dev machine, so a borderline test that just fit locally exceeds the default limit.

How to fix it

Fix the hang or raise the timeout

  1. Confirm every awaited promise resolves (mock network, advance fake timers).
  2. For legitimately slow tests, raise testTimeout globally or per test.
  3. Re-run to confirm the test completes.
vitest.config.ts
export default defineConfig({
  test: { testTimeout: 15000 },
})

Set a per-test timeout

Give one slow test more time without loosening the global default.

src/import.test.ts
it('imports a large dataset', async () => {
  // ...
}, 20000)

How to prevent it

  • Mock external I/O so tests do not wait on the network.
  • Advance fake timers instead of awaiting real delays.
  • Set a realistic testTimeout for the slowest legitimate tests.

Frequently asked questions

What causes ""Test timed out in 5000ms""?
An awaited call hangs (an unmocked network request, an unfired fake timer), so the test cannot complete before the timeout.
How do I fix "Test timed out in 5000ms"?
Fix the hang or raise the timeout

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card