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.

Opt-out of Jest FakeTimers

See original GitHub issue

Describe the feature you’d like:

I had to pin the DTL version to 7.29.4 in ATL because some tests that were using waitFor and waitForElementToBeRemoved were failing (I think this was also the root cause for https://github.com/testing-library/dom-testing-library/issues/901). This issue still persists to this date (I just tried to upgrade the DTL to its latest version).

After some time debugging, I think that the problem is that DTL falsely assumes that the Angular tests are using jest’s fake timers. This is because Angular patches the timers API.

Suggested implementation:

I would like to add an option to the config to opt-out of this behavior since I don’t see a better way to check if fake timers are used.

Describe alternatives you’ve considered:

Could we patch the useFakeTimers method, and use that to know if fake timers are used? This would replace the existing check.

Teachability, Documentation, Adoption, Migration Strategy:

/

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
MatanBobicommented, May 4, 2021

I like the suggestion @eps1lon as it decouples DTL from jest.

I agree that decoupling DTL from jest is a good idea, I’d prefer configuring the the test environment in the configure and not wrapping useFakeTimers and useRealTimers so users won’t need to adapt every test suite they have at the moment…

0reactions
IanVScommented, Jun 23, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

Timer Mocks - Jest
In the following example we enable fake timers by calling jest.useFakeTimers() . This is replacing the original implementation of ...
Read more >
Timeout when using jest "useFakeTimers" functionality #2200
We introduced an opt-in "modern" implementation of Fake Timers in Jest 26 accessed transparently through the same API, but with much more comprehensive...
Read more >
Disable Jest setTimeout mock - Stack Overflow
If I run jest.runAllTimers() , the timeout happens instantaneously, so fails to pick up the message. Any idea how to convince jest to...
Read more >
Timer Mocks - Jest - w3resource
In this case we enable fake timers by calling jest.useFakeTimers();. This will mock out setTimeout and other timer functions using mock ...
Read more >
@jest/fake-timers | Yarn - Package Manager
Fast, reliable, and secure dependency management.
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