Total Complexity | 10 |
Complexity/F | 1.11 |
Lines of Code | 46 |
Function Count | 9 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import Storage from '../../../src/utils/services/Storage'; |
||
2 | |||
3 | describe('Storage', () => { |
||
4 | const localStorageMock = { |
||
5 | getItem: jest.fn((key) => key === 'shlink.foo' ? JSON.stringify({ foo: 'bar' }) : null), |
||
|
|||
6 | setItem: jest.fn(), |
||
7 | }; |
||
8 | let storage; |
||
9 | |||
10 | beforeEach(() => { |
||
11 | localStorageMock.getItem.mockClear(); |
||
12 | localStorageMock.setItem.mockReset(); |
||
13 | |||
14 | storage = new Storage(localStorageMock); |
||
15 | }); |
||
16 | |||
17 | describe('set', () => { |
||
18 | it('writes an stringified representation of provided value in local storage', () => { |
||
19 | const value = { bar: 'baz' }; |
||
20 | |||
21 | storage.set('foo', value); |
||
22 | |||
23 | expect(localStorageMock.setItem).toHaveBeenCalledTimes(1); |
||
24 | expect(localStorageMock.setItem).toHaveBeenCalledWith('shlink.foo', JSON.stringify(value)); |
||
25 | }); |
||
26 | }); |
||
27 | |||
28 | describe('get', () => { |
||
29 | it('fetches item from local storage', () => { |
||
30 | storage.get('foo'); |
||
31 | expect(localStorageMock.getItem).toHaveBeenCalledTimes(1); |
||
32 | }); |
||
33 | |||
34 | it('returns parsed value when requested value is found in local storage', () => { |
||
35 | const value = storage.get('foo'); |
||
36 | |||
37 | expect(value).toEqual({ foo: 'bar' }); |
||
38 | }); |
||
39 | |||
40 | it('returns undefined when requested value is not found in local storage', () => { |
||
41 | const value = storage.get('bar'); |
||
42 | |||
43 | expect(value).toBeUndefined(); |
||
44 | }); |
||
45 | }); |
||
46 | }); |
||
47 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.