jest: Exceeded timeout of 5000 ms for a test
I am upgrading jest from v1.4.3 --> 2+, with chromedriver version 91+. I have started getting this issue:
thrown: "Exceeded timeout of 5000 ms for a test. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
I have been googling a lot but not getting proper solution. So, far I have tried following solutions:- 1)Increased jest.setTimeout(30000) from 30000 to 60000. 2)Tried using jest- testRunner": “jest-circus/runner”
My package.json configuration is as below: “@types/jest”: “26.0.23”, “@types/node”: “15.12.4”, “@types/selenium-webdriver”: “4.0.14”, “chromedriver”: “91.0.1”, “concurrently”: “6.2.0”, “jest”: “27.0.5”, “prettier”: “2.3.1”, “selenium-webdriver”: “4.0.0-alpha.7”, “ts-jest”: “27.0.3”, “tslint”: “6.1.3”, “tslint-config-prettier”: “^1.15.0”, “tslint-config-sparta”: “0.3.4”, “tslint-loader”: “3.5.4”, “typedoc”: “0.21.0”, “typescript”: “3.9.7”, “ui-testing-core”: “0.15.12”
Can anybody point out what is the solution?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 38
- Comments: 55 (2 by maintainers)
It seems to solve the problem.
Same problem, some solution is to add: jest.useFakeTimers(‘legacy’)
I ran @cBiscuitSurprise’s repro and was able to reproduce the issue with jest v27
Looks like
jest.setTimeout
is broken with that versionDid not work for me
Reading the changes to v27 here: https://jestjs.io/blog/2021/05/25/jest-27
jest.useRealTimers();
helped a bit, in the repro above, the first test passed with that option activatedthen for the other
The 10000 in the
it
block made the third test passLooks like we have a workaround for now?
Finally managed to increase the timeout by passing a third parameter to
test
:Both of them worked for me.
testTimeout: 20000
jest.setTimeout(30000);
before the describe blockIncrease Jest Timeout and it will work:
jest.setTimeout(30000)
outside of any block worked for me. it wasn’t working when i put it in thebeforeEach
jest.setTimeout(30000);
before thedescribe
block works for me. Others didn’t work.As noted in the Bug Report template, all bug reports requires a minimal reproduction. Please open up a new issue providing one. Read more at https://stackoverflow.com/help/minimal-reproducible-example.
adding jest.setTimeout(30000); before the describe block worked for me.
I’ve tried every single thing besides setting an explicit timeout for each
it.
The only thing that worked for me was setting"timers": "legacy"
in the config file!I had the 5000 ms timeout error in one of my tests, and it kept occurring even after setting
testTimeout: 10000
in my Jest config (the error message kept on saying “5000 ms”). Fortunately, in my case, callingjest.setTimeout(10000)
in the failing test made it pass – it’s settingtestTimeout
in the config that didn’t. I’m using Jest 27.2 on Windows 10.EDIT Interestingly, on Linux, it seems to be the opposite:
testTimeout
works butjest.setTimeout
doesn’t!It works like a champ
In my case I added a jest attribute in the package.json with the testTimeout property set a little higher have a look :
I can confirm that for my case,
testTimeout: any number
worked.Thank you very much guys
In my React Native project I had an issue where Jest was failing on
.start()
in my animation function:With the error:
thrown: "Exceeded timeout of 5000 ms for a test. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
So I added this after my imports in the Test file:
Then I added this to each test case:
Now it’s working again.
Heres an example:
Same for my react native project. The only thing working for me is the
jest.useFakeTimers('legacy')
@akauppi I have the same problem since we updated to Jest 27. I am on Windows 10 + WSL1 (Ubuntu), if that helps anyone.