-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
fix: Prevent "missing act" warning for queued microtasks #1137
Conversation
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 bfd1db7:
|
Codecov Report
@@ Coverage Diff @@
## alpha #1137 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 4
Lines 181 192 +11
Branches 34 38 +4
=========================================
+ Hits 181 192 +11
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
ab13864
to
065c316
Compare
065c316
to
fb22f8a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! :)
Hey! is there an ETA for this fix? We've ran into the bunch |
Would love to get this in soon to try and reduce the noise from our specs, then I can see if we have any "actual" act warnings left |
Hey @eps1lon, any chance this going to get merged soon? We are also facing some unexpected failing tests & act warnings after moving to RTL 13 (using the legacy root still). Thank you for your work 🙏 |
This is very helpful information, thank you! We have a new major planned that will include some small breaking changes from /dom. I was hesitant to merge this PR but including it in a new major makes it a lot safer to land. I'll clean this up, test on some larger repos and check how it performs. |
fb22f8a
to
d0da54c
Compare
if (jestFakeTimersAreEnabled()) { | ||
jest.advanceTimersByTime(0) | ||
} | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An observation: if I comment out this new await
code that drains the microtask queue, all the end-to-end.js
tests are still passing. Both macrotask and microtask, in all timer variants.
Seems the tests would need to be amended somehow to really reproduce the bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests in #1215
… where act() warnings are displayed incorrectly testing-library/react-testing-library#1137
@eps1lon Would it be possible to backport this to the 12.x release series for codebases still on React 17? |
@ak-beam this fix was only merged to alpha and isn't merged to master yet. |
What:
Closes #1125
Closes #1051
Why:
Once the
callback
passed towaitFor
resolves, there could be other microtasks scheduled.If we now yield back from
waitFor
we restore theREACT_IS_ACT_ENVIRONMENT
. However, the testerawait
s thewaitFor
and before the runtime yields back to the event loop, it needs (by spec) to drain the scheduled microtasks. This may include state updates which now run withoutREACT_IS_ACT_ENVIRONMENT
which triggers warning.How:
Drain microtask queue before resolving
waitFor
call.Checklist:
[ ]Documentation added to thedocs site
[ ]TypeScript definitions updated[ ] Test with React 17We no longer support React 17