Skip to content
Latchkey

Node "Timeout - Async callback was not invoked" in CI - Fix the Hanging Test

This timeout means an async test never signaled completion: a promise stayed pending or the done callback was never called within the test timeout.

What this error means

A test fails in CI with Timeout - Async callback was not invoked within the 5000 ms timeout. The test starts async work that never resolves, so it hangs until the limit.

node
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."

  Timeout - Async callback was not invoked within the 5000 ms timeout

Common causes

A promise that never settles

The test awaits or returns a promise that depends on a callback, network call, or event that never fires in CI.

A forgotten done() call

A callback-style test takes done but never calls it on every path, so the runner waits out the timeout.

How to fix it

Return or await the async work

  1. Make the test async and await the promise instead of mixing done with promises.
  2. Ensure the awaited work actually resolves.
JavaScript
it('loads data', async () => {
  const data = await load();
  expect(data).toBeDefined();
});

Call done on every path

  1. For callback-style tests, call done() in both success and error branches.
  2. Pass the error to done(err) on failure.

How to prevent it

  • Prefer async/await over the done callback, give genuinely slow tests an explicit timeout, and make sure mocked async work resolves so tests never hang in CI.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →