storage.js 482 B

123456789101112131415161718192021
  1. const makeStorageMock = function () {
  2. let store = {};
  3. return {
  4. store,
  5. getItem(key) {
  6. return store[key];
  7. },
  8. setItem(key, value) {
  9. store[key] = value;
  10. },
  11. clear() {
  12. store = {};
  13. }
  14. };
  15. };
  16. const localStorageMock = makeStorageMock();
  17. const sessionStorageMock = makeStorageMock();
  18. Object.defineProperty(window, 'localStorage', { value: localStorageMock });
  19. Object.defineProperty(window, 'sessionStorage', { value: sessionStorageMock });