FrontendAtlas
Study
▾
Dashboard
Pricing
Get full access
</> Code
Test cases
Language
JavaScript
TypeScript
export default function createCleanupBag() { // TODO: return { add, dispose, size } throw new Error('Not implemented'); }
import createCleanupBag from './createCleanupBag'; describe('createCleanupBag', () => { test('disposes remaining cleanups', () => { const bag = createCleanupBag(); const calls = []; const offA = bag.add(() => calls.push('a')); bag.add(() => calls.push('b')); offA(); bag.dispose(); expect(calls).toEqual(['b']); expect(bag.size()).toBe(0); }); test('dispose is idempotent', () => { const bag = createCleanupBag(); let count = 0; bag.add(() => count++); bag.dispose(); bag.dispose(); expect(count).toBe(1); }); test('add after dispose runs immediately', () => { const bag = createCleanupBag(); let ran = 0; bag.dispose(); bag.add(() => ran++); expect(ran).toBe(1); expect(bag.size()).toBe(0); }); });
▶ Run tests
Results
Console
Run tests to see results.