Skip to content
Latchkey

Jest "Exceeded timeout of 5000 ms for a test" in CI

A test did not finish within Jest's 5-second default. Usually a promise never resolves or an async value is not awaited/returned; less often the work is genuinely slower than the limit on a loaded runner.

What this error means

A specific test fails with "Exceeded timeout of 5000 ms for a test. Add a timeout value to this test..." It often passes locally but trips on slower CI, pointing at an unresolved async operation or a too-tight limit.

jest
thrown: "Exceeded timeout of 5000 ms for a test.
Add a timeout value to this test to increase the timeout, if this is a
long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."

Common causes

A promise that never settles

An awaited promise - a mocked fetch never resolved, a pending event - never settles, so the test hangs until the timeout fires.

Async not returned or awaited

The test does async work but neither returns the promise nor awaits it (nor calls done), so Jest cannot tell when it finished.

Genuinely slow work in CI

A real network/DB call or heavy computation legitimately exceeds 5s, especially on a loaded shared runner.

How to fix it

Await the work and resolve mocks

Make completion observable and ensure every mocked promise resolves or rejects.

data.test.ts
it('loads data', async () => {
  fetchMock.mockResolvedValueOnce({ ok: true });
  await expect(loadData()).resolves.toEqual({ ok: true });
});

Raise the timeout only for truly slow tests

Terminal
// per test (third argument, ms)
it('slow integration', async () => { /* ... */ }, 20000);
// or globally
jest.setTimeout(20000);

How to prevent it

  • Always return or await async work; prefer async/await over done.
  • Use fake timers for time-based logic instead of real waits.
  • Set a sensible global timeout and override only where justified.

Frequently asked questions

What causes ""Exceeded timeout of 5000 ms""?
An awaited promise - a mocked fetch never resolved, a pending event - never settles, so the test hangs until the timeout fires.
How do I fix "Exceeded timeout of 5000 ms"?
Make completion observable and ensure every mocked promise resolves or rejects.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.

Related guides

References

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