Skip to content

Commit c89a578

Browse files
authored
test(cache): verify TTLCache throws RangeError for negative TTL (JhaSourav07#1398) (JhaSourav07#1883)
## Description Added a specific test case in lib/cache.test.ts to verify that setting a cache value with a negative TTL (e.g., -5000) correctly throws a RangeError. This improves test coverage for boundary inputs and ensures the TTLCache implementation behaves safely under extreme values, satisfying all acceptance criteria for the issue. Fixes JhaSourav07#1398 ## Pillar - [ ] 🎨 Pillar 1 — New Theme Design - [ ] 📐 Pillar 2 — Geometric SVG Improvement - [ ] 🕐 Pillar 3 — Timezone Logic Optimization - [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview <img width="947" height="420" alt="Screenshot 2026-05-31 005643" src="https://github.com/user-attachments/assets/15dd2a6f-f510-49cd-bccb-f76657b3f4e2" /> ## Checklist before requesting a review: [x] I have read the CONTRIBUTING.md file. [x] I have tested these changes locally (localhost:3000/api/streak?user=YOUR_USERNAME). [x] I have run npm run format and npm run lint locally and resolved all errors (CI will fail otherwise). [x] My commits follow the Conventional Commits format (e.g., feat(themes): ..., fix(calculate): ...). [x] I have updated README.md if I added a new theme or URL parameter. [x] I have started the repo. [x] I have made sure that i have only one commit to merge in this PR. [x] The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts). [x] (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.
2 parents 9218ab8 + d6e4432 commit c89a578

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

lib/cache.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,13 @@ describe('TTLCache', () => {
426426
});
427427

428428
describe('edge cases and error handling', () => {
429+
// FIX: New test explicitly targeting the -5000 boundary for Issue #1398
430+
it('throws RangeError when setting a value with -5000 TTL', () => {
431+
const cache = new TTLCache<string>();
432+
expect(() => cache.set('key', 'value', -5000)).toThrow(RangeError);
433+
cache.destroy();
434+
});
435+
429436
it('throws RangeError when ttlMs is 0 or negative', () => {
430437
const cache = new TTLCache<string>();
431438
expect(() => cache.set('key', 'value', 0)).toThrow(RangeError);
@@ -473,6 +480,7 @@ describe('TTLCache', () => {
473480
expect([null, 'lived']).toContain(result);
474481
cache.destroy();
475482
});
483+
476484
it('does not throw when ttlMs is Number.EPSILON', () => {
477485
const cache = new TTLCache<string>();
478486

0 commit comments

Comments
 (0)