No waitForNextUpdate ? #1101
Copy link
Copy link
Closed as not planned
Description
Hi all,
I've briefly checked the docs and discord to check that and it sees that waitForNextUpdate is not available as return of renderHook for now in testing library.
Is there a plan to implement that or testing async hooks is considered as bad practice?
If it won't be implemented maybe theres an option to inform about it in the docs, as it seems to be main feature for testing async hooks
Thank you for what you do with the lib.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
eps1lon commentedon Jul 28, 2022
the next update isn't necessarily relevant to the user. We want to discourage testing these implementation in Testing Library.
waitForhas all the tools you need.srosato commentedon Sep 15, 2023
@eps1lon is right on the
waitFor, though since we are testing hooks, sometimes it might be harder to test what is relevent to a user since testing a hook is arguably in some way testing implementation details.Here is an example of an upgrade I did (code simplified).
From:
To:
mirismaili commentedon Oct 5, 2023
This is my previous test on Apollo's useQuery using
waitForNextUpdate:It was working well.
Now, how do I write it w/o
waitForNextUpdate?MatanBobi commentedon Oct 29, 2023
@mirismaili you can use
waitForfor that.What about trying:
That should work.
likeuwill commentedon Nov 10, 2023
To mock apollo queries and make it work in test
useDocument tests: update to latest recommended pattern
useDocument tests: update to latest recommended pattern
useDocument tests: update to latest recommended pattern
elyobo commentedon Apr 2, 2024
waitFor+expectcan breakexpect.assertions()expectations, as it may result in more assertions than expected due to retriesgithorse commentedon Jul 6, 2024
I don't see how
waitForis a replacement forwaitForNextUpdateat all.waitFordoesn't say anything about how many re-renders happened before I got there. The argument here seems to be that the internals of the hook and its behavior are a black box, and I should only test the dom. Nice idea, but it's critical that I understand and control how many render cycles are triggered by my hook. Is that possible under the new paradigm?By way of example: I've just spent several days implementing some hooks based around Tanstack Query with selectors/transformations to ensure that consumers of the hook are only reloaded when their relevant slice of the underlying data is mutated (a la useContextSelector). It's a critical performance consideration for my app. How can I test that with this library?
githorse commentedon Jul 17, 2024
Well, here's one way:
chore(tests): fix `generic/data/apiHooks` tests
chore(tests): fix `generic/data/apiHooks` tests
chore(tests): fix `generic/data/apiHooks` tests
chore(tests): fix `generic/data/apiHooks` tests
chore(tests): fix `generic/data/apiHooks` tests
fix(tests): fix warnings in use-promise.test.tsx
fix(tests): fix warnings in use-promise.test.tsx
fix(tests): fix warnings in use-promise.test.tsx
fix(tests): fix warnings in use-promise.test.tsx
fix(tests): fix warnings in use-promise.test.tsx
fix(tests): fix warnings in use-promise.test.tsx
fix(tests): fix warnings in use-promise.test.tsx
fix(tests): fix warnings in use-promise.test.tsx
fix(tests): fix warnings in use-promise.test.tsx