Async callback was not invoked within the 5000ms timeout - Error Message Improvement
🐛 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.
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
I doubt that "Most commonly this is being caused by conflicting Promise implementations" is still up-to-date advice given that custom Promise implementations do not seem to be very popular anymore. We should probably not further promote this hint if it won't actually help most users. Are you sure your problems were caused by this if you don't actually use a Promise library? Based on your screenshot it looks like the Promises really just take too long to resolve (hard to tell ofc)
I'm using Karma with Jasmine and I am experiencing the same issue. I spent a few hours trying to figure it out but eventually realized it was caused by a mix between the Angular.js $q promise library and native Promises.
FWIW I would appreciate it if this was documented somewhere so that people like us don't have to dig for hours before finding the cause of the problem.
This is what I'm getting, but sometimes it all goes well.
Timeout - Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Error:
package.json
"jest": {
"preset": "react-native",
"setupFiles": [
"<rootDir>/__tests__/setup.js"
],
setup.js
jest.setTimeout(1000 * 60 * 10);
"react": "16.9.0",
"react-native": "0.60.4",
"jest": "^24.8.0",
I had same problem and tried using jest.setTimeout(30000) and also global.Promise = jest.requireActual('promise'); but still getting same error, when i noticed i had mockAxios.post.mockImplentationOnce() instead of mockAxios.get.mockImplentationOnce(), silly mistake but easily overlooked
I had same problem and tried using jest.setTimeout(30000) and also global.Promise = jest.requireActual('promise'); but still getting same error, when i noticed i had mockAxios.post.mockImplentationOnce() instead of mockAxios.get.mockImplentationOnce(), silly mistake but easily overlooked
Interesting, did it fail every time or randomly?
Having random issue with this also, always on an Axios mocked implementation
System:
OS: macOS Mojave 10.14.4
CPU: (8) x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Binaries:
Node: 10.15.0 - ~/.nvm/versions/node/v10.15.0/bin/node
npm: 6.9.0 - ~/.nvm/versions/node/v10.15.0/bin/npm
npmPackages:
jest: ~22.4.4 => 22.4.4
I found my problem. Babel bootsrap was huge, it take more than 10 seconds on the first run. Since this test is waiting for an Axios promise, it didn't respond in time, I pushed the setTimeout and it avoid the problem. Now we need to understand why importing es2015 syntax import is so costly.
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 -
-
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 needresetAllMocks()for that -
I was using
mockImplementationOnce()to blindly mock a whole series of tests (in abeforeEach()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();
});
Thanks @abhchand,
Moxios was causing this issue on my side.
🐛 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.
![]()
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/awaitso we are not using any promise libraries directly. However, I can see some are in ournode_modulesdirectory.> ls node_modules | grep "promise" p-is-promise request-promise-core request-promise-nativeMy 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 jestPaste 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
To solve this Issue I just added "jest": { "testTimeout": 120000 } in package.json file
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days.
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.