Skip to content

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

Closed as not planned
@krutoo

Description

@krutoo

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions