-
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] Migrate test suites to account for testing library upgrades security-entity-analytics #201178
base: main
Are you sure you want to change the base?
[React18] Migrate test suites to account for testing library upgrades security-entity-analytics #201178
Conversation
/ci |
3aec23a
to
ca64f75
Compare
/ci |
Pinging @elastic/security-entity-analytics (Team:Entity Analytics) |
@elasticmachine merge upstream |
1 similar comment
@elasticmachine merge upstream |
@elasticmachine merge upstream |
1 similar comment
@elasticmachine merge upstream |
@elasticmachine merge upstream |
4 similar comments
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
…ary owned by security-entity-analytics
8df8789
to
1d07dce
Compare
@elasticmachine merge upstream |
…-entity-analytics
@elasticmachine merge upstream |
…-entity-analytics
💚 Build Succeeded
Metrics [docs]
History
cc @eokoneyo |
This PR migrates test suites that use
renderHook
from the library@testing-library/react-hooks
to adopt the equivalent and replacement ofrenderHook
from the export that is now available from@testing-library/react
. This work is required for the planned migration to react18.Context
In this PR, usages of
waitForNextUpdate
that previously could have been destructured fromrenderHook
are now been replaced withwaitFor
exported from@testing-library/react
, furthermorewaitFor
that would also have been destructured from the same renderHook result is now been replaced with
waitFor
from the export of@testing-library/react
.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
thateffectively 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 a
waitFor(() => new Promise((resolve) => resolve(null)))
(many thanks to @kapral18, for point out exactly why this works),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 pointing out this PR might also contain changes to test and application code to improve said existing test.
What to do next?
Any questions?
If you have any questions or need help with this PR, please leave comments in this PR.