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.
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 timeoutCommon 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
- Make the test async and await the promise instead of mixing done with promises.
- Ensure the awaited work actually resolves.
it('loads data', async () => {
const data = await load();
expect(data).toBeDefined();
});Call done on every path
- For callback-style tests, call done() in both success and error branches.
- 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.