diff --git a/lib/cache.test.ts b/lib/cache.test.ts index ed7bdc01..24af74f5 100644 --- a/lib/cache.test.ts +++ b/lib/cache.test.ts @@ -549,6 +549,23 @@ describe('TTLCache', () => { cache.destroy(); }); + // FIX: New test targeting the NaN boundary for Issue #1399 + it('resolves NaN TTL to the default standard TTL duration', () => { + vi.useFakeTimers(); + const cache = new TTLCache(); + + // Setting with NaN should not throw; it should fallback to the default TTL + expect(() => cache.set('nan-key', 'value', NaN)).not.toThrow(); + + // The item should be successfully stored + expect(cache.get('nan-key')).toBe('value'); + + // Advance by a small amount to ensure it didn't instantly expire + vi.advanceTimersByTime(1000); + expect(cache.get('nan-key')).toBe('value'); + + cache.destroy(); + }); it('verify TTLCache behavior for infinite TTL value (Variation 1)', () => { const cache = new TTLCache();