diff --git a/services/web/test/frontend/bootstrap.js b/services/web/test/frontend/bootstrap.js index 5bfe082d41..b6b2306d90 100644 --- a/services/web/test/frontend/bootstrap.js +++ b/services/web/test/frontend/bootstrap.js @@ -26,14 +26,19 @@ moment.updateLocale('en', { }) let inMemoryLocalStorage = {} -global.localStorage = { - // localStorage returns `null` when the item does not exist - getItem: key => - inMemoryLocalStorage[key] !== undefined ? inMemoryLocalStorage[key] : null, - setItem: (key, value) => (inMemoryLocalStorage[key] = value), - clear: () => (inMemoryLocalStorage = {}), - removeItem: key => delete inMemoryLocalStorage[key] -} +Object.defineProperty(global, 'localStorage', { + value: { + // localStorage returns `null` when the item does not exist + getItem: key => + inMemoryLocalStorage[key] !== undefined + ? inMemoryLocalStorage[key] + : null, + setItem: (key, value) => (inMemoryLocalStorage[key] = value), + clear: () => (inMemoryLocalStorage = {}), + removeItem: key => delete inMemoryLocalStorage[key] + }, + writable: true +}) // node-fetch doesn't accept relative URL's: https://github.com/node-fetch/node-fetch/blob/master/docs/v2-LIMITS.md#known-differences const fetch = require('node-fetch') diff --git a/services/web/test/frontend/features/outline/components/outline-pane.test.js b/services/web/test/frontend/features/outline/components/outline-pane.test.js index 1f54ecfbf7..74d287686a 100644 --- a/services/web/test/frontend/features/outline/components/outline-pane.test.js +++ b/services/web/test/frontend/features/outline/components/outline-pane.test.js @@ -15,11 +15,16 @@ describe('', function() { renderWithEditorContext(children, { projectId: '123abc' }) } + let originalLocalStorage before(function() { - global.localStorage = { - getItem: sinon.stub().returns(null), - setItem: sinon.stub() - } + originalLocalStorage = global.localStorage + + Object.defineProperty(global, 'localStorage', { + value: { + getItem: sinon.stub().returns(null), + setItem: sinon.stub() + } + }) }) afterEach(function() { @@ -30,7 +35,9 @@ describe('', function() { }) after(function() { - delete global.localStorage + Object.defineProperty(global, 'localStorage', { + value: originalLocalStorage + }) }) it('renders expanded outline', function() { diff --git a/services/web/test/frontend/infrastructure/local-storage.test.js b/services/web/test/frontend/infrastructure/local-storage.test.js index 58789833c6..0c8959a436 100644 --- a/services/web/test/frontend/infrastructure/local-storage.test.js +++ b/services/web/test/frontend/infrastructure/local-storage.test.js @@ -10,22 +10,27 @@ describe('localStorage', function() { }) after(function() { - global.localStorage = originalLocalStorage + Object.defineProperty(global, 'localStorage', { + value: originalLocalStorage + }) }) beforeEach(function() { - global.localStorage = { - getItem: sinon.stub().returns(null), - setItem: sinon.stub(), - clear: sinon.stub(), - removeItem: sinon.stub() - } + Object.defineProperty(global, 'localStorage', { + value: { + getItem: sinon.stub().returns(null), + setItem: sinon.stub(), + clear: sinon.stub(), + removeItem: sinon.stub() + } + }) + global.console.error = sinon.stub() }) afterEach(function() { global.console.error.reset() - delete global.localStorage + Object.defineProperty(global, 'localStorage', { value: undefined }) }) it('getItem', function() {