export async function waitFor( predicate: () => boolean | Promise, options: { timeoutMs?: number; intervalMs?: number; message?: string; } = {}, ): Promise { const timeoutMs = options.timeoutMs ?? 500; const intervalMs = options.intervalMs ?? 5; const deadline = Date.now() + timeoutMs; while (Date.now() < deadline) { if (await predicate()) { return; } await new Promise((resolve) => setTimeout(resolve, intervalMs)); } throw new Error(options.message ?? "Timed out waiting for test condition"); }