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

Make selectOption work when fake timers are enabled #4604

Merged
merged 2 commits into from
Mar 8, 2024

Conversation

dskloetd
Copy link
Contributor

@dskloetd dskloetd commented Mar 8, 2024

Motivation

While cleaning up a test in another branch, I discovered that userEvent.selectOption doesn't work when fake timers are enabled.

I found a work-around here: testing-library/user-event#833

userEvent.setup({ advanceTimers: jest.advanceTimersByTime })

It also seems that vitest does not expose a way to test if fake timers are enabled, but fake timers specific method throw if fake timers are not enabled so this can be used to detect if fake timers are enabled.

Changes

  1. Add a function areFakeTimersEnabled to check if fake timers are enabled.
  2. If fake timers are enabled, use the work-around to use userEvent.selectOption in JestPageObjectElement.selectOption.

Tests

Used in another branch to stop a test from timing out after enabling fake timers.

Todos

  • Add entry to changelog (if necessary).

@dskloetd dskloetd marked this pull request as ready for review March 8, 2024 13:44
Copy link
Contributor

@mstrasinskis mstrasinskis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dskloetd dskloetd added this pull request to the merge queue Mar 8, 2024
Merged via the queue into main with commit 6715474 Mar 8, 2024
50 checks passed
@dskloetd dskloetd deleted the kloet/select-fake-timers branch March 8, 2024 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants