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.

Combining jsdom testEnvironment and fake timers results in timeout errors

See original GitHub issue

Describe 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

  1. Clone the reproduction.
  2. npm install
  3. 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:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
dcalhouncommented, Jul 20, 2022

Hello, we also have the same problem and as @AugustinLF pointed out, where can we found the upgrade guide for this version ? We are not aware of what action should be done to succeed an upgrade to jest 27.

@kopax-polyconseil there are two options:

  1. Change your Jest configuration to testEnvironment: 'node' and address any incompatibility in your test (e.g. DOM references).
  2. Continue using 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.

0reactions
kopax-polyconseilcommented, Jul 20, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

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