Jest "Exceeded timeout of 5000 ms for a test"
A test did not finish within Jest’s 5-second default. Usually a promise never resolves, an async value is not awaited/returned, or a done callback is never called - less often the work is genuinely slower than the limit.
What this error means
A specific test fails with "Exceeded timeout of 5000 ms for a test. Add a timeout value..." or "thrown: Exceeded timeout". It often passes locally but trips in slower CI, hinting at an unresolved async operation.
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 that is never resolved, a pending event) never settles, so the test hangs until the timeout fires.
Async not returned or awaited
A test does async work but neither returns the promise nor awaits it (or calls done), so Jest cannot tell when it is finished.
Genuinely slow work
A real network/DB call or heavy computation legitimately exceeds 5s, especially on a loaded CI runner.
How to fix it
Await/return the async work and resolve mocks
Make the test’s completion observable, and ensure every mocked promise actually resolves or rejects.
it('loads data', async () => {
fetchMock.mockResolvedValueOnce({ ok: true });
await expect(loadData()).resolves.toEqual({ ok: true });
});Raise the timeout for genuinely slow tests
// 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.