jest.setTimeout has no effect
See original GitHub issueDescribe the bug
When using jest.setTimeout()
in a long-running async test, this has no effect in create-react-app
.
When running the exact same test once in create-react-app
, and once only using jest
directly, the following error is thrown with create-react-app
:
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."
With jest
alone, the test passes.
This seems to be related to changes from 3.4.4
to 4.0.0
, since when running the same test against react-scripts
version 3.4.4
, the test also passes.
Did you try recovering your dependencies?
Yes
Which terms did you search for in User Guide?
timeout
, setTimeout
=> no results
Environment
Environment Info:
current version of create-react-app: 4.0.0
running from /Users/fm/.npm/_npx/61035/lib/node_modules/create-react-app
System:
OS: macOS 10.15.7
CPU: (8) x64 Intel(R) Core(TM) i7-8559U CPU @ 2.70GHz
Binaries:
Node: 12.19.0 - ~/.nvm/versions/node/v12.19.0/bin/node
Yarn: 1.22.5 - ~/.yarn/bin/yarn
npm: 6.14.8 - ~/.nvm/versions/node/v12.19.0/bin/npm
Browsers:
Chrome: 86.0.4240.198
Edge: Not Found
Firefox: 81.0.2
Safari: 14.0.1
npmPackages:
react: 17.0.1 => 17.0.1
react-dom: 17.0.1 => 17.0.1
react-scripts: 4.0.0 => 4.0.0
npmGlobalPackages:
create-react-app: Not Found
Steps to reproduce
Jest only
- Clone repository
issue-timeout-jest
npm install
npm run test
(passes as expected)
with CRA
- Clone repository
issue-timeout-cra
npm install
npm run test
Expected behavior
Test should pass:
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Actual behavior
Test fails, the following error is thrown:
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."
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Reproducible demo
issue-timeout-jest
: https://github.com/martinfrancois/issue-timeout-jest
issue-timeout-cra
: https://github.com/martinfrancois/issue-timeout-cra
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:6
Top Results From Across the Web
Jest 27: jest.setTimeout has no effect when used in async test ...
I had the same problem and was able to (temporarily) resolve it by moving the jest.setTimeout(...) to the top level scope, i.e. outside...
Read more >Jest unit test: setTimeout not firing in async test - Stack Overflow
After going through the JEST timer mocks documentation, it occurred to me that the setTimeout goes into infinite recursion as mentioned in the ......
Read more >Mocking setTimeout with Jest. | Medium - Marek Rozmus
We could increase timeout for unit tests but it is not a good practice. Usually when test exceeds timeout, it means that it...
Read more >Fix the "not wrapped in act(...)" warning with Jest fake timers
Because that's happening outside of the React call stack, React doesn't know when it's time to flush all the state updates, run all...
Read more >Testing Asynchronous Code - Jest
... before it can move on to another test. Jest has several ways to handle this. ... Otherwise, a fulfilled promise would not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Possible workarounds here:
it
. I.e.,it('runs slow', () => {...}, 10000)
jest.setTimeout(10000);
in a file named src/setupTests.js, as specified here.Having the same issue. We do visual regression tests for components via Jest and after upgrading to react scripts 4.0.0 all tests fail, because they regularly take longer than 5 seconds. We definitely need a fix for this.