question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async callback was not invoked within the 5000ms timeout - Error Message Improvement

See original GitHub issue

🐛 Bug Report

I have some tests which have always passed until a recent merge. They now show the following error:

Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.

However I can see that the tests do indeed finish and are not long running.

Screenshot 2019-04-26 at 16 24 08

Having read https://jestjs.io/docs/en/troubleshooting#unresolved-promises I can see that this issue may in-fact relate more to having multiple promise libraries being used. As a relatively recent project all of our code uses async/await so we are not using any promise libraries directly. However, I can see some are in our node_modules directory.

> ls node_modules | grep "promise"
p-is-promise
request-promise-core
request-promise-native

My bug report pertains to the above error message, perhaps we could improve it by adding a link to the documentation that explains that multiple promise implementations could be an issue (I spent over an hour trying to solve this issue before coming across this information) 👍.

In addition, I think it would be good to add some more information to the docs site about why this happens and more detailed information for how to resolve if you, like I, are in a position where you don’t use any promise libraries and frankly don’t know where to start to debug this issue.

If anyone could chime in to let me know what I should do next I would be more than happy to submit PRs to improve the relevant error message and associated docs. 😄

Run npx envinfo --preset jest

Paste the results here:

  System:
    OS: macOS Mojave 10.14.4
    CPU: (4) x64 Intel(R) Core(TM) i5-7600 CPU @ 3.50GHz
  Binaries:
    Node: 11.12.0 - /usr/local/bin/node
    Yarn: 1.15.2 - /usr/local/bin/yarn
    npm: 6.7.0 - /usr/local/bin/npm

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:33
  • Comments:9

github_iconTop GitHub Comments

5reactions
abhchandcommented, Aug 15, 2020

I had this same issue -

  • Running a whole suite of tests would cause a particular set of tests to fail
  • Running those tests individually was successful
  • All the “failing” tests use axios.post.mockImplementationOnce()

The issue was two things in combination -

  1. I was not resetting all mocks properly. clearAllMocks() only resets the calls count of each mock, it doesn’t truly reset the mock implementations. You need resetAllMocks() for that

  2. I was using mockImplementationOnce() to blindly mock a whole series of tests (in a beforeEach() block) and they were not getting invoked in some of the tests.

Because the mocks never got called in some tests, their mocked return values leaked into other tests since they were never properly reset between tests.

This might not be the exact solution to this issue, but hopefully it helps someone who searches and comes across this same issue.

afterEach(() => { 
  jest.clearAllMocks(); 
  jest.resetAllMocks();
});
2reactions
flowckcommented, Mar 29, 2021

Thanks @abhchand,

Moxios was causing this issue on my side.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Message "Async callback was not invoked within the 5000 ms ...
Sometimes, when I run the tests, everything works as expectedly. Other times, I get an error: Timeout - Async callback was not invoked...
Read more >
Async callback was not invoked within the 5000ms timeout not ...
For anyone experiencing the same issue with jest puppeteer tests, I found a workaround to make the failure message display the line where...
Read more >
Jest testing with Node – Timeout – Async callback was not ...
Javascript – Message “Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout”. The timeout you specify here needs to...
Read more >
Troubleshooting · Jest
If a promise doesn't resolve at all, this error might be thrown: - Error: Timeout - Async callback was not invoked within timeout...
Read more >
async callback was not invoked within the 5000 ms timeout ...
settimeout.timeout. Add Answer | View In TPC Matrix. Technical Problem Cluster First Answered On February 20, 2021 Popularity 10/10 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found