File size: 615 Bytes
aa89cb5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { LocalCache } from '../src/core/local-cache';

describe('LocalCache', () => {
  beforeEach(() => jest.useFakeTimers());
  afterEach(() => jest.useRealTimers());

  it('shares values, removes entries, and expires TTL entries', () => {
    const cache = new LocalCache();
    cache.put('persistent', { id: 7 });
    expect(cache.get<{ id: number }>('persistent')).toEqual({ id: 7 });
    cache.remove('persistent');
    expect(cache.get('persistent')).toBeUndefined();

    cache.put('temporary', 'value', 1);
    jest.advanceTimersByTime(1_000);
    expect(cache.get('temporary')).toBeUndefined();
  });
});