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]: Looks like injectGlobals: false affects fake timers #14868

Closed
krutoo opened this issue Jan 25, 2024 · 3 comments
Closed

[Bug]: Looks like injectGlobals: false affects fake timers #14868

krutoo opened this issue Jan 25, 2024 · 3 comments

Comments

@krutoo
Copy link

krutoo commented Jan 25, 2024

Version

29.7.0

Steps to reproduce

  1. clone https://github.com/krutoo/testing-library-user-event-with-fake-timers
  2. `npm install
  3. npm run test

Expected behavior

Tests done

Actual behavior

line

await user.click(getByTestId("counter"));

won't resolve and test fails by timeout with error:

thrown: "Exceeded timeout of 5000 ms for a test.
    Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."

Additional context

I noticed that in @testing-library/user-event library there is some code like this:

Promise.all([
    new Promise((resolve) => {
        globalThis.setTimeout(() => resolve(), delay)
    }),
    config.advanceTimers(delay)
]);

config.advanceTimers is option - https://testing-library.com/docs/user-event/options/#advancetimers

This promise resolves as expected but in test there is no resolve or reject, it just freezes.

I think this is because fake timers affects microtasks mechanism or something else.

Environment

System:
    OS: Linux 6.5 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i9-11900K @ 3.50GHz
  Binaries:
    Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
    bun: 1.0.12 - ~/.bun/bin/bun
  npmPackages:
    jest: ^29.7.0 => 29.7.0
@signorettif
Copy link

FWIW, I think this is a testing-library issue, not a jest one. I have opened an issue with the relative explanation and possible fixes in: testing-library/dom-testing-library#1286 .

@SimenB
Copy link
Member

SimenB commented Feb 16, 2024

Yeah, nothing in jest itself breaks on missing globals, so downstream assumptions are almost certainly where things go awry

@SimenB SimenB closed this as not planned Won't fix, can't repro, duplicate, stale Feb 16, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants