diff --git a/packages/happy-dom/src/storage/StorageFactory.ts b/packages/happy-dom/src/storage/StorageFactory.ts index 7b94c7121..499977746 100644 --- a/packages/happy-dom/src/storage/StorageFactory.ts +++ b/packages/happy-dom/src/storage/StorageFactory.ts @@ -12,31 +12,20 @@ export default class StorageFactory { * Creates a new storage. */ public static createStorage(): Storage { - const boundMethods: { [k: string]: (...arg) => any } = {}; - const boundGetters: { [k: string]: () => any } = {}; - // Documentation for Proxy: // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy return new Proxy(new Storage(), { get(storage: Storage, key: string): string | number | boolean | Function { if (Storage.prototype.hasOwnProperty(key)) { - if (boundMethods[key] !== undefined) { - return boundMethods[key]; - } - if (boundGetters[key] !== undefined) { - return boundGetters[key](); - } const descriptor = Object.getOwnPropertyDescriptor(Storage.prototype, key); if (descriptor.value !== undefined) { if (typeof descriptor.value === 'function') { - boundMethods[key] = storage[key].bind(storage); - return boundMethods[key]; + return storage[key].bind(storage); } return descriptor.value; } if (descriptor.get) { - boundGetters[key] = descriptor.get.bind(storage); - return boundGetters[key](); + return descriptor.get.call(storage); } return storage[key]; } diff --git a/packages/happy-dom/test/storage/Storage.test.ts b/packages/happy-dom/test/storage/Storage.test.ts index e4718ce50..cffa1a6da 100644 --- a/packages/happy-dom/test/storage/Storage.test.ts +++ b/packages/happy-dom/test/storage/Storage.test.ts @@ -161,7 +161,7 @@ describe('Storage', () => { }); it('Should be able to spy on prototype methods.', () => { - Storage.prototype.getItem = vi.fn(() => 'mocked'); + vi.spyOn(Storage.prototype, 'getItem').mockImplementation(() => 'mocked'); expect(storage.getItem('key1')).toBe('mocked'); });