Skip to content

Commit 4b20ff0

Browse files
authored
test(cache): verify near-zero positive TTL values do not throw (JhaSourav07#1126)
## Description Added tests to verify that very small positive TTL values such as `Number.EPSILON` and `0.0001` do not throw errors in `TTLCache#set()`. Fixes JhaSourav07#1096 ## Pillar * [x] 🛠️ Other (Bug fix, refactoring, docs) ## Visual Preview Not applicable. Test-only change. ## Checklist * [x] I have read the `CONTRIBUTING.md` file. * [x] I have tested these changes locally. * [x] I have run `npm run format` and `npm run lint` locally and resolved all errors. * [x] My commit follows the Conventional Commits format. * [x] I have made sure that I have only one commit to merge in this PR.
2 parents c5b2b75 + 9eee012 commit 4b20ff0

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

lib/cache.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,25 @@ describe('TTLCache', () => {
381381
expect([null, 'lived']).toContain(result);
382382
cache.destroy();
383383
});
384+
it('does not throw when ttlMs is Number.EPSILON', () => {
385+
const cache = new TTLCache<string>();
386+
387+
expect(() => {
388+
cache.set('key', 'value', Number.EPSILON);
389+
}).not.toThrow();
390+
391+
cache.destroy();
392+
});
393+
394+
it('does not throw when ttlMs is a very small positive number', () => {
395+
const cache = new TTLCache<string>();
396+
397+
expect(() => {
398+
cache.set('key', 'value', 0.0001);
399+
}).not.toThrow();
400+
401+
cache.destroy();
402+
});
384403

385404
it('multiple clear operations work correctly', () => {
386405
const cache = new TTLCache<string>();

0 commit comments

Comments
 (0)