Waits for a function to successfully resolve, within a given timeout.
npm i @code-like-a-carpenter/wait-for
import {waitFor} from '@code-like-a-carpenter/wait-for';
const result = await waitFor(async () => {
return await loadSlowThingFromTheDatabase();
}, 20000);
const validatedResult = await waitFor(async () => {
const item = await loadSlowThingFromTheDatabase();
expect(item).toBeDefined();
expect(item.id).toBe(1);
return item;
}, 20000);
Please see contributing guidelines at the project homepage.
MIT © Ian Remmel 2023 until at least now