method
test.Expect.poll
fn: () => T,
options?: { interval: number; message: string; timeout: number }
): Omit<AsyncMatchers<Awaited<T>>, 'resolves' | 'rejects' | 'toThrow' | 'toThrowError' | 'toMatchSnapshot' | 'toMatchInlineSnapshot' | 'toThrowErrorMatchingSnapshot' | 'toThrowErrorMatchingInlineSnapshot'>;
Calls fn, awaits its result and runs the matcher on it. Retries until the matcher passes. The matcher returns a promise that rejects with the last failure once timeout is up.
The wait uses the real clock, even with fake timers on. Each attempt advances the fake timers by interval.
await expect.poll(() => document.querySelector(".ready")).not.toBeNull();
await expect.poll(() => queue.length, { interval: 10, timeout: 500 }).toBe(0);Referenced types
type AsyncMatchers<T = unknown> = MatchersBuiltin<T, Promise<void>> & { [K in Exclude<keyof Matchers<T>, keyof MatchersBuiltin>]: Matchers<T>[K] extends (...args: infer Args) => unknown ? (...args: Args) => Promise<void> : Matchers<T>[K] } & Matchers<T>
The matchers available after .resolves and .rejects. Each one returns a promise that fulfills if the matcher passes and rejects with the failure if it doesn't.