2020-05-20 08:07:52 -04:00
|
|
|
import { useLocalStorageSpy } from './local_storage_helper';
|
|
|
|
|
2020-08-27 14:10:29 -04:00
|
|
|
describe('block before helper is installed', () => {
|
|
|
|
it('should leave original localStorage intact', () => {
|
|
|
|
expect(localStorage.getItem).toEqual(expect.any(Function));
|
|
|
|
expect(jest.isMockFunction(localStorage.getItem)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
2020-05-20 08:07:52 -04:00
|
|
|
|
|
|
|
describe('localStorage helper', () => {
|
2020-08-27 14:10:29 -04:00
|
|
|
useLocalStorageSpy();
|
|
|
|
|
2020-05-20 08:07:52 -04:00
|
|
|
it('mocks localStorage but works exactly like original localStorage', () => {
|
|
|
|
localStorage.setItem('test', 'testing');
|
|
|
|
localStorage.setItem('test2', 'testing');
|
|
|
|
|
|
|
|
expect(localStorage.getItem('test')).toBe('testing');
|
|
|
|
|
|
|
|
localStorage.removeItem('test', 'testing');
|
|
|
|
|
|
|
|
expect(localStorage.getItem('test')).toBeUndefined();
|
|
|
|
expect(localStorage.getItem('test2')).toBe('testing');
|
|
|
|
|
|
|
|
localStorage.clear();
|
|
|
|
|
|
|
|
expect(localStorage.getItem('test2')).toBeUndefined();
|
|
|
|
});
|
|
|
|
});
|