Combining jsdom testEnvironment and fake timers results in timeout errors
See original GitHub issueDescribe the bug
Combining testEnvironment: 'jsdom'
and fake timers, regardless of “legacy” or “modern” timers, results in timeout errors. It would appear that setImmediate
does not perform as expected, breaking the built-in cleanup
functionality of @testing-library/react-native
.
This issue occurs in Jest 27, not Jest 26. Jest 27 includes a fair number of changes, including changes to setImmediate
.
Error Details
> rntl-jsdom-fake-timers@0.0.1 test
> jest
PASS ./node-real-timers.test.js
PASS ./node-fake-timers.test.js
PASS ./jsdom-real-timers.test.js
FAIL ./jsdom-fake-timers.test.js (5.829 s)
● jsdom test environment with fake timers › does not timeout
thrown: "Exceeded timeout of 5000 ms for a hook.
Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."
3 | */
4 |
> 5 | import "@testing-library/react-native";
| ^
6 |
7 | beforeEach(() => {
8 | jest.useFakeTimers();
at Object.<anonymous> (node_modules/@testing-library/react-native/build/index.js:29:3)
at Object.<anonymous> (jsdom-fake-timers.test.js:5:1)
Test Suites: 1 failed, 3 passed, 4 total
Tests: 1 failed, 3 passed, 4 total
Snapshots: 0 total
Time: 6.732 s
Ran all test suites.
Expected behavior
Combining @testing-library/react-native
, testEnvironment: 'jsdom'
, and fake timers does not cause tests to fail with timeout errors.
Steps to Reproduce
- Clone the reproduction.
npm install
npm run test
Screenshots
n/a
Versions
npmPackages:
@testing-library/react-native: ^9.0.0 => 9.0.0
react: 17.0.2 => 17.0.2
react-native: 0.66.4 => 0.66.4
react-test-renderer: 17.0.2 => 17.0.2
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Jest error with timers: environment has been torn down
... after a timeout. I've been using jest and specifically fake timers for few years now, but this is the first time I...
Read more >Configuring Jest
This will be used to configure minimum threshold enforcement for coverage results. Thresholds can be specified as global , as a glob, and...
Read more >jest-environment-jsdom | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >Frontend testing standards and style guidelines - GitLab Docs
We use Jest to write frontend unit and integration tests. Jest tests can be found in /spec/frontend and /ee/spec/frontend in EE. Limitations of...
Read more >Frontend testing · Testing guide · Development · Help · GitLab
Running yarn jest-debug runs Jest in debug mode, allowing you to debug/inspect as described in the Jest docs. Timeout error. The default timeout...
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
@kopax-polyconseil there are two options:
testEnvironment: 'node'
and address any incompatibility in your test (e.g. DOM references).testEnvironment: 'jsdom'
and replace RNTL usage with React Testing Library.Option 1 is ideal if achievable for your code, as tests will run faster.
Also, you may be able to mix both options by setting the testing environment for individual files as needed with a comment in a given test file.
You misunderstood me, this module console-fail-test is not a logger, it is meant to fail test if they are logs.
I have described the issue here since we tried the upgrade to jest 27, we are unable to fix it : https://github.com/Codecademy/console-fail-test/issues/72#issuecomment-1190356938
Perhaps you have a hint for us, I don’t have any idea atm yet.