Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: runWithRealTimers activates fake Timers #886

Closed
ph-fritsche opened this issue Feb 3, 2021 · 0 comments
Closed

bug: runWithRealTimers activates fake Timers #886

ph-fritsche opened this issue Feb 3, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@ph-fritsche
Copy link
Member

  • @testing-library/dom version: master = v7.29.4

Relevant code or config:

https://github.com/ph-fritsche/dom-testing-library/blob/24ebf282d10782b3d0a22b939a1b2950d4b5bd1b/src/__tests__/helpers.js#L86-L118

What you did:

Tried to fix #884

What happened:

The test leaks setTimeout only if jest.useFakeTimers('modern') has been used in some other test before.

Reproduction:

See relevant code above and parent commits.

Problem description:

Stopping the leak is not sufficient as the side-effect is in the tested unit.

The assumption that jest.getRealSystemTime() could be used to determine if a modern jest fake timer is active is wrong.

// jest.getRealSystemTime is only supported for Jest's `modern` fake timers and otherwise throws
jest.getRealSystemTime()
return 'modern'

Suggested solution:

Determine if a jest fake timer is active by calling jest.useRealTimers() and observing the change of global timer functions.

ph-fritsche added a commit to ph-fritsche/dom-testing-library that referenced this issue Feb 3, 2021
ph-fritsche added a commit to ph-fritsche/dom-testing-library that referenced this issue Feb 3, 2021
ph-fritsche added a commit to ph-fritsche/dom-testing-library that referenced this issue Feb 3, 2021
@nickserv nickserv added the bug Something isn't working label Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants