UNPKG

1.34 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var Storage = /** @class */ (function () {
4 function Storage() {
5 this.getItem = jest.fn(this.unmockedGetItem);
6 this.setItem = jest.fn(this.unmockedSetItem);
7 this.removeItem = jest.fn(this.unmockedRemoveItem);
8 this.clear = jest.fn(this.unmockedClearItem);
9 this.store = Object.create(null);
10 }
11 Storage.prototype.restore = function () {
12 this.getItem.mockClear();
13 this.getItem.mockImplementation(this.unmockedGetItem);
14 this.setItem.mockClear();
15 this.setItem.mockImplementation(this.unmockedSetItem);
16 this.removeItem.mockClear();
17 this.removeItem.mockImplementation(this.unmockedRemoveItem);
18 this.clear.mockClear();
19 this.clear.mockImplementation(this.unmockedClearItem);
20 this.clear();
21 };
22 Storage.prototype.unmockedGetItem = function (key) {
23 return this.store[key] || null;
24 };
25 Storage.prototype.unmockedSetItem = function (key, value) {
26 this.store[key] = value.toString();
27 };
28 Storage.prototype.unmockedRemoveItem = function (key) {
29 delete this.store[key];
30 };
31 Storage.prototype.unmockedClearItem = function () {
32 this.store = {};
33 };
34 return Storage;
35}());
36exports.default = Storage;