diff --git a/ui/src/setupTests.js b/ui/src/setupTests.js index df5f363d4..84f521dcd 100644 --- a/ui/src/setupTests.js +++ b/ui/src/setupTests.js @@ -4,17 +4,24 @@ // learn more: https://github.com/testing-library/jest-dom import '@testing-library/jest-dom/extend-expect' -class LocalStorageMock { - constructor() { - this.store = {} - } - getItem(key) { - return this.store[key] || null - } - setItem(key, value) { - this.store[key] = String(value) - } -} +const localStorageMock = (function () { + let store = {} + + return { + getItem: function (key) { + return store[key] || null + }, + setItem: function (key, value) { + store[key] = value.toString() + }, + clear: function () { + store = {} + }, + } +})() + +Object.defineProperty(window, 'localStorage', { + value: localStorageMock, +}) -global.localStorage = new LocalStorageMock() localStorage.setItem('username', 'admin')