From 9b0676ec15a26d5fadd96880c54994c38609e969 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Thu, 26 Jun 2025 16:49:13 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85(jest)=20fix=20window.location=20mock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We upgraded to jest 30.0.3. This upgrade updated jsdom and jsdom now do not allows to mock window.location. See: https://github.com/jsdom/jsdom/issues/3492 This commit fixes this issue. --- .../src/features/auth/__tests__/utils.test.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/frontend/apps/impress/src/features/auth/__tests__/utils.test.tsx b/src/frontend/apps/impress/src/features/auth/__tests__/utils.test.tsx index 2aa0a02c..3a9b28b3 100644 --- a/src/frontend/apps/impress/src/features/auth/__tests__/utils.test.tsx +++ b/src/frontend/apps/impress/src/features/auth/__tests__/utils.test.tsx @@ -24,13 +24,22 @@ describe('utils', () => { }); it('checks support session is terminated when logout', () => { + jest.spyOn(console, 'error').mockImplementation(() => {}); + window.$crisp = true; - Object.defineProperty(window, 'location', { + const propertyDescriptors = Object.getOwnPropertyDescriptors(window); + for (const key in propertyDescriptors) { + propertyDescriptors[key].configurable = true; + } + const clonedWindow = Object.defineProperties({}, propertyDescriptors); + + Object.defineProperty(clonedWindow, 'location', { value: { ...window.location, replace: jest.fn(), }, writable: true, + configurable: true, }); gotoLogout();