You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Assuming the above was passing correctly, it would reference the jest global object, which is undefined when not injecting globals. This would lead to an error when attempting to invoke jest.advanceTimersByTime.
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:
The second issue could be addressed by dynamically attempting to import jest from @jest/globals when (a) we detect a JEST_WORKER_ID and (b) we know fake timers are enabled.
I don't believe dom-testing-library should depend on @jest/globals.
I'm not completely satisfied with the tentative dynamic import of an optional dependency @jest/globals in this case, but I think it might provide the best developer experience for end users.
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.
The text was updated successfully, but these errors were encountered:
@testing-library/dom
version:9.3.4
jest@29.7.0
jest-environment-jsdom@29.7.0
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:
jest
to not inject globals (--injectGlobals=false
); refer to thepackage.json
command from the sandbox above.waitFor
orwaitForElementToBeRemoved
.Outcome:
waitFor
never advances timers by time (the default50ms
interval of the loop or any other interval), causing the tests to exceed their timeout.Reproduction:
You can reproduce this issue via the following codesandbox link.
Problem Description:
When using
jest
, but without injecting globals, thewaitFor
logic:jest
's environment in thejestFakeTimersAreEnabled
predicate.jest
global object, which is undefined when not injecting globals. This would lead to an error when attempting to invokejest.advanceTimersByTime
.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:
jest
environment detection) can be resolved by adding anOR
condition to thejestFakeTimersAreEnabled
predicate. In my experience, we should add a check forprocess.env.JEST_WORKER_ID
to not beundefined
.jest
from@jest/globals
when (a) we detect aJEST_WORKER_ID
and (b) we know fake timers are enabled.dom-testing-library
should depend on@jest/globals
.@jest/globals
in this case, but I think it might provide the best developer experience for end users.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.The text was updated successfully, but these errors were encountered: