react-testing-library icon indicating copy to clipboard operation
react-testing-library copied to clipboard

feat: add advanceTimers option

Open mihkeleidast opened this issue 6 months ago • 2 comments

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)
  • [x] Tests (can improve, if provided a bit of guidance)
  • [x] TypeScript definitions updated
  • [x] Ready to be merged

mihkeleidast avatar Jun 10 '25 21:06 mihkeleidast

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 9099fe3f2d5e9a2d6ebe74167beb7251f4bef6a1:

Sandbox Source
react-testing-library-examples Configuration

codesandbox-ci[bot] avatar Jun 10 '25 21:06 codesandbox-ci[bot]

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.

mihkeleidast avatar Jun 10 '25 21:06 mihkeleidast