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: wojtekmaj/react-async-button@fa41b3b
Suggested solution:
After long debug session, I have determined that
|
// Drain microtask queue. |
|
// Otherwise we'll restore the previous act() environment, before we resolve the `waitFor` call. |
|
// The caller would have no chance to wrap the in-flight Promises in `act()` |
|
await new Promise(resolve => { |
|
setTimeout(() => { |
|
resolve() |
|
}, 0) |
|
|
|
if (jestFakeTimersAreEnabled()) { |
|
jest.advanceTimersByTime(0) |
|
} |
|
}) |
- Moving
if (jestFakeTimersAreEnabled()) { ... } to wrap the entire block mentioned above resolves the issue.
- Calling
vi.advanceTimersByTime(0); manually after user.click(...) but before awaiting returned promise, even multiple times, does NOT help
- The only workaround that worked for me was this: wojtekmaj/react-async-button@2d26f21
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.
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: wojtekmaj/react-async-button@fa41b3b
Suggested solution:
After long debug session, I have determined that
asyncWrapperto be justcb => cb()resolves the issue.react-testing-library/src/pure.js
Lines 41 to 52 in f78839b
if (jestFakeTimersAreEnabled()) { ... }to wrap the entire block mentioned above resolves the issue.vi.advanceTimersByTime(0);manually afteruser.click(...)but beforeawaiting returned promise, even multiple times, does NOT helpSo my suggestion is to:
if (jestFakeTimersAreEnabled()) { ... }to wrap the entire block mentioned above, acknowledging that the fix is now Jest-only.