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 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.
JavaScript
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.
Related guides
Node EADDRINUSE "address already in use" for a Test Server in CI - Fix Port ConflictsFix the Node.js EADDRINUSE "address already in use" error for a test server in CI by closing the previous lis…
Node UnhandledPromiseRejection Crashes the Job in CI - Handle the RejectionFix Node.js UnhandledPromiseRejection crashes in CI by awaiting or catching the rejecting promise so the proc…
Node AssertionError in CI - Fix the Failed InvariantFix the Node.js AssertionError in CI by correcting the value that violates the assertion or fixing the assert…