Skip to content

feat: add advanceTimers option #1402

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mihkeleidast
Copy link

@mihkeleidast mihkeleidast commented Jun 10, 2025

What: adding a new advanceTimers configuration option to resolve #1197

Possibly also #1393 and #1187, but maintainers are smarter than me about this, whether it also covers those.

Why: as this is currently not configurable, users have to use various workarounds to be able to use this library with vitest and fake timers, e.g.mock jest globals when they are not using jest

How:

  • Added a new configuration option, advanceTimers, with the same name and signature that user-event already uses: https://github.com/testing-library/user-event/blob/main/src/options.ts#L127. Using the same name and signature should ensure best ecosystem compatibility.
  • Moved existing jest fake timers check and timers advancing to config and defined it as the default config value. This ensures existing code continues working as expected.

Checklist:

  • Documentation added to the docs site (can do, if needed, once this is approved in principle)
  • Tests (can improve, if provided a bit of guidance)
  • TypeScript definitions updated
  • Ready to be merged

Copy link

codesandbox-ci bot commented Jun 10, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 9099fe3:

Sandbox Source
react-testing-library-examples Configuration

@mihkeleidast mihkeleidast marked this pull request as ready for review June 10, 2025 21:38
@mihkeleidast
Copy link
Author

I don't believe the experimental react version test failures are due to these changes, as they also fail on main if I install experimental react & react-dom locally. But let me know if there's something I could do.

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.

Update to v14 breaks @testing-library/user-event on Vitest
1 participant