testing-library / testing-library/react-testing-library
Update to v14 breaks @testing-library/user-event on Vitest
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 19.7k
- Forks
- 1.2k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 1
Description
What you did:
A simple update from v13 to v14 broke my Vitest-based test where I was using await user.click(...) as the promise no longer resolves.
Reproduction:
Run repo at the following commit: https://github.com/wojtekmaj/react-async-button/commit/fa41b3b9900a25d76141bcf2080f94f7ee5f5dee
Suggested solution:
After long debug session, I have determined that
- Monkey patching
asyncWrapperto be justcb => cb()resolves the issue. - Removing the following code added in testing-library/react-testing-library#1137 resolves the issue:
- Moving
if (jestFakeTimersAreEnabled()) { ... }to wrap the entire block mentioned above resolves the issue. - Calling
vi.advanceTimersByTime(0);manually afteruser.click(...)but beforeawaiting returned promise, even multiple times, does NOT help - The only workaround that worked for me was this: https://github.com/wojtekmaj/react-async-button/commit/2d26f217a375b7020ddf42f76891254586fc3ce4
So my suggestion is to:
- Roll back the fix and perhaps reintroduce when advanceTimers will be configurable and not jest dependent
- OR move
if (jestFakeTimersAreEnabled()) { ... }to wrap the entire block mentioned above, acknowledging that the fix is now Jest-only.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the reproduction at commit fa41b3b9900a25d76141bcf2080f94f7ee5f5dee and inspect src/pure.js, especially the block linked at lines 41-52. Compare the v13 and v14 user-event behavior under Vitest, then verify that awaiting user.click(...) resolves without relying only on Jest-specific timer handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100