Evgeniy Pozdnyakov
Evgeniy Pozdnyakov

Reputation: 73

React testing library how to use waitFor with a Promise

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

Upvotes: 0

Views: 1808

Answers (1)

Toni Bardina Comas
Toni Bardina Comas

Reputation: 1808

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')

Upvotes: 2

Related Questions