mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-02 21:45:14 +01:00
32 lines
706 B
TypeScript
32 lines
706 B
TypeScript
import { Cache } from '../src/cache';
|
|
|
|
const delay = (ms: number) => jest.advanceTimersByTime(ms);
|
|
|
|
const TTL = 100;
|
|
|
|
describe('Cache', () => {
|
|
let cache: Cache;
|
|
|
|
beforeEach(() => {
|
|
jest.useFakeTimers();
|
|
cache = new Cache();
|
|
});
|
|
|
|
it('set and get', () => {
|
|
cache.set('key', 'value', TTL);
|
|
expect(cache.get('key')).toEqual('value');
|
|
});
|
|
|
|
it('get with expired TTL', () => {
|
|
cache.set('key', 'value', TTL);
|
|
delay(TTL + 1);
|
|
expect(cache.get('key')).toBeUndefined();
|
|
});
|
|
|
|
it('delete', () => {
|
|
cache.set('key', 'value', TTL);
|
|
cache.delete('key');
|
|
expect(cache.get('key')).toBeUndefined();
|
|
});
|
|
});
|