Skip to content

Commit 6b5bed5

Browse files
committed
test(utils): add performance utility tests
1 parent 8b381be commit 6b5bed5

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { memoize, lazy } from '../../utils/performance';
3+
describe('performance', () => {
4+
describe('memoize', () => {
5+
it('caches results', () => { let calls = 0; const fn = memoize((x: unknown) => { calls++; return x; }); fn(1); fn(1); expect(calls).toBe(1); });
6+
it('recomputes for new args', () => { let calls = 0; const fn = memoize((_x: unknown) => { calls++; return calls; }); fn(1); fn(2); expect(calls).toBe(2); });
7+
});
8+
describe('lazy', () => { it('creates lazily', () => { let created = false; const get = lazy(() => { created = true; return 42; }); expect(created).toBe(false); expect(get()).toBe(42); expect(created).toBe(true); }); });
9+
});

0 commit comments

Comments
 (0)