testing-library / dom-testing-library

🐙 Simple and complete DOM testing utilities that encourage good testing practices.
https://testing-library.com/dom
MIT License
3.25k stars 460 forks source link

`waitFor` doesn't advance time when using `jest` fake timers without injecting globals #1286

Open signorettif opened 5 months ago

signorettif commented 5 months ago

Relevant Code or Config:

A minimal sandbox to reproduce the issue is available on codesandbox. You can execute tests by opening a terminal and running the yarn test command.

Actions Undertaken:

Outcome:

Reproduction:

You can reproduce this issue via the following codesandbox link.

Problem Description:

When using jest, but without injecting globals, the waitFor logic:

On a broader scope (although I want to keep this issue's focus narrow for the sake of actionability), there might be other unintended implicit assumptions about depending on (a) jest and / or (b) a test environment that injects globals. The following issues are related, although they focus on different manifested problems:

Suggested Solution:

Depending on the appetite for this issue to be fixed, I might work on a PR to address the above. I am somewhat surprised this hasn't come up before, but I guess not many people tend to set up jest without injecting globals.

krutoo commented 4 months ago

@signorettif May this ussue be relative to this problem? https://github.com/testing-library/user-event/issues/1173

signorettif commented 4 months ago

Yes! I think that's a symptom of the same underlying problem

krutoo commented 1 month ago

@signorettif is there some updates?

MatanBobi commented 1 month ago

In the end, it all boils down to whether TL should be open to dependency injection of the advance timers function by our users. There's been some talk about this here: https://github.com/testing-library/dom-testing-library/issues/939

I didn't get the change to work on that lately.