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

.click() not working when injectGlobals: false and fake timers enabled #1173

Open
krutoo opened this issue Oct 18, 2023 · 4 comments
Open

.click() not working when injectGlobals: false and fake timers enabled #1173

krutoo opened this issue Oct 18, 2023 · 4 comments
Labels
bug Something isn't working needs assessment This needs to be looked at by a team member

Comments

@krutoo
Copy link

krutoo commented Oct 18, 2023

Reproduction example

https://github.com/krutoo/testing-library-user-event-with-fake-timers

Prerequisites

  1. clone repo
  2. npm install
  3. npm run test

Expected behavior

Tests should be done

Actual behavior

Test fails by timeout 5000ms

User-event version

14.5.1

Environment

Testing Library framework: @testing-library/react@12.1.3

JS framework: react@18.2.0

Test environment: jest@29.7.0

DOM implementation: jest-environment-jsdom@29.7.0

Additional context

In jest config I use injectGlobals: false and may be its the reason

I also use userEvent.setup({ advanceTimers: jest.advanceTimersByTime }) and its not solves issue.

@krutoo krutoo added bug Something isn't working needs assessment This needs to be looked at by a team member labels Oct 18, 2023
@krutoo krutoo changed the title click not working when injectGlobals: false and fake timers enabled .click() not working when injectGlobals: false and fake timers enabled Oct 18, 2023
@krutoo
Copy link
Author

krutoo commented Jan 19, 2024

Can anyone confirm or deny?

@korniux
Copy link

korniux commented Jan 25, 2024

Can reproduce

@K3TH3R
Copy link

K3TH3R commented Feb 21, 2024

I'm also seeing this happening with Vitest's vi.useFakeTimers(). I insert vi.useFakeTimers() globally as part of my setupFiles as I have a lot of date/time related tests, so the tests that are using userEvent.setup(), if I put vi.useRealTimers() at the start of the unit test, it allows them to run properly again.

@K3TH3R
Copy link

K3TH3R commented Mar 11, 2024

I'm also seeing this happening with Vitest's vi.useFakeTimers(). I insert vi.useFakeTimers() globally as part of my setupFiles as I have a lot of date/time related tests, so the tests that are using userEvent.setup(), if I put vi.useRealTimers() at the start of the unit test, it allows them to run properly again.

Update: I'm not doing vi.useFakeTimers() globally anymore and I'm still seeing this issue when I use vi.useFakerTimers() in a test that I use userEvent.setup() in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs assessment This needs to be looked at by a team member
Projects
None yet
Development

No branches or pull requests

3 participants