|
1 | 1 | import { Cache } from './cache'; |
2 | 2 |
|
3 | | -describe("cache.ts - Cache", ()=>{ |
| 3 | +describe('cache.ts - Cache', () => { |
| 4 | + let cache: Cache; |
| 5 | + let setSpy: jest.SpyInstance; |
4 | 6 |
|
5 | | - let cache : Cache |
6 | | - let setSpy : jest.SpyInstance |
7 | | - |
8 | | - beforeAll(()=>{ |
9 | | - cache = new Cache({enabled : true}) |
| 7 | + beforeAll(() => { |
| 8 | + cache = new Cache({ enabled: true }); |
10 | 9 | setSpy = jest.spyOn(Cache.prototype, 'set'); |
| 10 | + }); |
11 | 11 |
|
12 | | - }) |
13 | | - |
14 | | - it("should return undefined when cache is disabled", ()=>{ |
15 | | - cache = new Cache({enabled : false}) |
| 12 | + it('should return undefined when cache is disabled', () => { |
| 13 | + cache = new Cache({ enabled: false }); |
16 | 14 | expect(cache.get('test')).toBeUndefined(); |
17 | | - }) |
| 15 | + }); |
18 | 16 |
|
19 | | - it("should return undefined when cache is enabled but key is not cached", ()=>{ |
20 | | - cache = new Cache({enabled : true}) |
| 17 | + it('should return undefined when cache is enabled but key is not cached', () => { |
| 18 | + cache = new Cache({ enabled: true }); |
21 | 19 | expect(cache.get('test')).toBeUndefined(); |
22 | | - }) |
| 20 | + }); |
23 | 21 |
|
24 | | - |
25 | | - it("should return the cached value when cache is enabled and key is in cache", ()=>{ |
| 22 | + it('should return the cached value when cache is enabled and key is in cache', () => { |
26 | 23 | const cache = new Cache({ enabled: true, size: 1, ttl: 1 }); |
27 | 24 | cache.set('test', { value: true, reason: 'test' }); |
28 | 25 | expect(cache.get('test')).toEqual({ value: true, reason: 'test' }); |
29 | | - }) |
| 26 | + }); |
30 | 27 |
|
31 | | - it("should not set any value when cache is disabled", ()=>{ |
| 28 | + it('should not set any value when cache is disabled', () => { |
32 | 29 | expect(setSpy).not.toHaveBeenCalled(); |
33 | | - }) |
| 30 | + }); |
34 | 31 |
|
35 | | - it("should clear the cache when cache is enabled and .clear() is called", ()=>{ |
| 32 | + it('should clear the cache when cache is enabled and .clear() is called', () => { |
36 | 33 | const cache = new Cache({ enabled: true, size: 1, ttl: 1 }); |
37 | 34 | cache.set('test', { value: true, reason: 'test' }); |
38 | 35 | cache.clear(); |
39 | 36 | expect(cache.get('test')).toBeUndefined(); |
40 | | - }) |
41 | | - |
42 | | - afterEach(()=>{ |
43 | | - cache = new Cache({enabled : true}) |
44 | | - jest.clearAllMocks() |
45 | | - }) |
46 | | -}) |
| 37 | + }); |
47 | 38 |
|
| 39 | + afterEach(() => { |
| 40 | + cache = new Cache({ enabled: true }); |
| 41 | + jest.clearAllMocks(); |
| 42 | + }); |
| 43 | +}); |
0 commit comments