-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[React18] use waitFor with assertion callbacks in place of waitForNextUpdate #195087
[React18] use waitFor with assertion callbacks in place of waitForNextUpdate #195087
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
⏳ Build in-progress, with failures
Failed CI Steps
Test Failures
HistoryTo update your PR or re-run it, just comment with: cc @eokoneyo |
dbc6b43
to
eef0bd1
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
eef0bd1
to
a9b2787
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
a9b2787
to
535ef46
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
faddbad
to
1999867
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
1999867
to
c22e275
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
5859357
to
048f99a
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
1 similar comment
This comment was marked as duplicate.
This comment was marked as duplicate.
048f99a
to
a20d08d
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
a20d08d
to
6976880
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
6976880
to
d06fc18
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
1 similar comment
This comment was marked as duplicate.
This comment was marked as duplicate.
d06fc18
to
e94f0e1
Compare
6979ee6
to
b6887e9
Compare
b6887e9
to
03243d9
Compare
⏳ Build in-progress, with failures
Failed CI StepsTest Failures
History
cc @eokoneyo |
Hi all, thanks for all the feedback... given that initially I'd had to patch |
Summary
This PR swaps usages of
waitForNextUpdate
exported from@testing-library/react-hooks
forwaitFor
exported from@testing-library/react
as part of the work being done to upgrade to react 18.For context; on updating to react 18 there will be a need to update
@testing-library/react
and in turn the hook renderer, however the hook renderer does not expose the afore-mentioned methodwaitForNextUpdate
hence why we are preemptively adopting this approach.Why is
waitFor
a sufficient enough replacement forwaitForNextUpdate
, and better for testing values subject to async computations?WaitFor will retry the provided callback if an error is returned, till the configured timeout elapses. By default the retry interval is
50ms
with a timeout value of1000ms
that effectively translates to at least 20 retries for assertions placed within waitFor. See https://testing-library.com/docs/dom-testing-library/api-async/#waitfor for more information.This however means that for person's writing tests, said person has to be explicit about expectations that describe the internal state of the hook being tested. This implies checking for instance when a react query hook is being rendered, there's an assertion that said hook isn't loading anymore.
In this PR you'd notice that this pattern has been adopted, with most existing assertions following an invocation of
waitForNextUpdate
being placed within awaitFor
invocation. In some cases the replacement is simply awaitFor(() => null)
where this suffices the assertions that follow aren't placed within a waitFor so this PR doesn't get larger than it needs to be.it's also worth mentioning that an eslint rule has been included to prevent further usages of
waitForNextUpdate
and destructuring or directly usages ofwaitFor
from therenderHook
function, pending the migration to the newer version of therenderHook
to prevent any further work relating to this. Furthermore there were some modification to certain test suites to ensure the test is indeed testing the thing it claimed to test.