From cf3f0145a6d01a10e84dff6c8cf3d369eb7e7b1a Mon Sep 17 00:00:00 2001 From: Hugo Duthil Date: Mon, 14 Sep 2020 18:11:08 +0200 Subject: [PATCH] Restore window.localStorage property descriptor after each test --- test/spec/unit/core/storageManager_spec.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/test/spec/unit/core/storageManager_spec.js b/test/spec/unit/core/storageManager_spec.js index 2e6833bae50..de09df5b196 100644 --- a/test/spec/unit/core/storageManager_spec.js +++ b/test/spec/unit/core/storageManager_spec.js @@ -46,18 +46,16 @@ describe('storage manager', function() { describe('localstorage forbidden access in 3rd-party context', function() { let errorLogSpy; + const originalLocalStorage = { get: () => window.localStorage }; + const localStorageMock = { get: () => { throw Error } }; beforeEach(function() { - var mock = { - get: function() { - throw Error; - } - }; - Object.defineProperty(window, 'localStorage', mock); + Object.defineProperty(window, 'localStorage', localStorageMock); errorLogSpy = sinon.spy(utils, 'logError'); }); afterEach(function() { + Object.defineProperty(window, 'localStorage', originalLocalStorage); errorLogSpy.restore(); })