Skip to content

bug: runWithRealTimers activates fake Timers #886

Closed
@ph-fritsche

Description

@ph-fritsche
  • @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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions