[React18] use waitFor with assertion callbacks in place of waitForNextUpdate#195087
[React18] use waitFor with assertion callbacks in place of waitForNextUpdate#195087eokoneyo wants to merge 26 commits intoelastic:mainfrom
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
8e6d029 to
7c3f402
Compare
sabarasaba
left a comment
There was a problem hiding this comment.
kibana management changes lgtm 🚀
⏳ 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
waitForNextUpdateexported from@testing-library/react-hooksforwaitForexported from@testing-library/reactas 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/reactand in turn the hook renderer, however the hook renderer does not expose the afore-mentioned methodwaitForNextUpdatehence why we are preemptively adopting this approach.Why is
waitFora 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
50mswith a timeout value of1000msthat 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
waitForNextUpdatebeing placed within awaitForinvocation. 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
waitForNextUpdateand destructuring or directly usages ofwaitForfrom therenderHookfunction, pending the migration to the newer version of therenderHookto 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.