From da3993f3dd75830628cf44e3d41a4e7ac68610bd Mon Sep 17 00:00:00 2001 From: "Sakamoto, Kazunori" Date: Wed, 4 Dec 2024 20:36:35 +0900 Subject: [PATCH] test: improve tests --- tests/unit/memoize.test.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/unit/memoize.test.ts b/tests/unit/memoize.test.ts index 5f3bb44..4c631e1 100644 --- a/tests/unit/memoize.test.ts +++ b/tests/unit/memoize.test.ts @@ -125,21 +125,29 @@ describe('persistent cache', () => { cacheDuration: 200, })((base: number = 0): number => base + getNextInteger()); - beforeEach(() => { - persistentStore.clear(); + function clearCache(): void { for (const cache of caches) { cache.clear(); } + } + + beforeEach(() => { + persistentStore.clear(); + clearCache(); }); test('should use persistent cache', () => { const initial = nextIntegerWithPersistence(100); + clearCache(); + expect(nextIntegerWithPersistence(100)).toBe(initial); expect(persistentStore.size).toBe(1); }); test('should remove expired cache', async () => { const initial = nextIntegerWithPersistence(100); + clearCache(); + expect(persistentStore.size).toBe(1); await setTimeout(400); const second = nextIntegerWithPersistence(100); @@ -150,6 +158,8 @@ describe('persistent cache', () => { test('should handle multiple cache entries', () => { const value1 = nextIntegerWithPersistence(100); const value2 = nextIntegerWithPersistence(200); + clearCache(); + expect(persistentStore.size).toBe(2); expect(nextIntegerWithPersistence(100)).toBe(value1); expect(nextIntegerWithPersistence(200)).toBe(value2); @@ -166,6 +176,7 @@ describe('persistent cache', () => { const value1 = withSizeLimit(100); const value2 = withSizeLimit(200); const value3 = withSizeLimit(300); + clearCache(); expect(persistentStore.size).toBe(2); expect(withSizeLimit(300)).toBe(value3);