FrontendAtlas
Study
▾
Dashboard
Pricing
Get full access
</> Code
Test cases
Language
JavaScript
TypeScript
export default function pollUntil(check, options = {}) { // TODO: poll until check returns a truthy value or rejects on timeout/abort throw new Error('Not implemented'); }
import pollUntil from './pollUntil'; describe('pollUntil', () => { test('resolves when check becomes truthy', async () => { let count = 0; const result = await pollUntil(() => { count += 1; return count >= 3 ? 'ready' : false; }, { interval: 5, timeout: 50 }); expect(result).toBe('ready'); }); test('supports async checks', async () => { let count = 0; const result = await pollUntil(async () => { count += 1; await new Promise((r) => setTimeout(r, 2)); return count === 2 ? 42 : false; }, { interval: 5, timeout: 50 }); expect(result).toBe(42); }); test('rejects on timeout', async () => { await expect( pollUntil(() => false, { interval: 5, timeout: 20 }) ).rejects.toThrow('Timeout'); }); test('rejects when aborted', async () => { const ac = new AbortController(); const p = pollUntil(() => false, { interval: 5, signal: ac.signal }); setTimeout(() => ac.abort(), 10); await expect(p).rejects.toMatchObject({ name: 'AbortError' }); }); });
▶ Run tests
Results
Console
Run tests to see results.