React testing library how to use waitFor with a Promise

Viewed 133

I understand how to use waitFor with a simple function, but I can't imaging a good use case to use it with a Promise. Do you have an idea? TY

1 Answers

waitFor will wait for the callback to not throw an error, so you can always await the promise inside waitFor.

await waitFor(async () => await new Promise(...))

Btw most of the time you can just await the promise without the need for waitFor. A good example would be the findBy methods:

await findBy('#someId')
Related