FrontendAtlas
Study
▾
Dashboard
Pricing
Get full access
</> Code
Test cases
Language
JavaScript
TypeScript
export default async function runWithPerfBudget(fn, budgetMs, now) { throw new Error('Not implemented'); }
import runWithPerfBudget from './runWithPerfBudget'; describe('runWithPerfBudget', () => { test('times sync functions and returns ok status', async () => { const times = [100, 112]; const now = () => times.shift(); const res = await runWithPerfBudget(() => 123, 20, now); expect(res).toEqual({ ok: true, durationMs: 12, value: 123 }); }); test('times async functions and awaits the result', async () => { const times = [0, 50]; const now = () => times.shift(); const res = await runWithPerfBudget(async () => 'ok', 40, now); expect(res.ok).toBe(false); expect(res.durationMs).toBe(50); expect(res.value).toBe('ok'); }); test('clamps negative duration to 0', async () => { const times = [10, 5]; const now = () => times.shift(); const res = await runWithPerfBudget(() => 'x', 0, now); expect(res.durationMs).toBe(0); expect(res.ok).toBe(true); }); test('throws on invalid inputs', async () => { await expect(runWithPerfBudget(null, 1)).rejects.toThrow(); await expect(runWithPerfBudget(() => 1, -1)).rejects.toThrow(); }); });
▶ Run tests
Results
Console
Run tests to see results.