From cb47717b090414715c5167c4d9ec651a3dd60be8 Mon Sep 17 00:00:00 2001 From: Mubbshar Anwar <78487564+mubbsharanwar@users.noreply.github.com> Date: Thu, 6 Apr 2023 10:35:46 +0500 Subject: [PATCH] fix: window console warning (#830) remove console log warnings from SocialAuthProviders unit tests by mocking the location object. Mock localStorage. VAN-1350 --- src/setupTest.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/setupTest.js b/src/setupTest.js index 01bff849..63fb7bf9 100755 --- a/src/setupTest.js +++ b/src/setupTest.js @@ -39,3 +39,27 @@ window.ResizeObserver = ResizeObserver; window.scrollTo = (x, y) => { document.documentElement.scrollTop = y; }; + +const location = new URL('https://authn.edx.org'); +location.assign = jest.fn(); +location.replace = jest.fn(); +location.reload = jest.fn(); +delete window.location; +window.location = location; + +const localStorageMock = jest.fn(() => { + let store = {}; + return { + getItem: (key) => (store[key] || null), + setItem: (key, value) => { + store[key] = value.toString(); + }, + clear: () => { + store = {}; + }, + removeItem: (key) => { + delete store[key]; + }, + }; +})(); +Object.defineProperty(window, 'localStorage', { value: localStorageMock });