From 1d531d5a36ea7aeae9171b6a14b8e615f8ac51d1 Mon Sep 17 00:00:00 2001 From: Jerome Date: Fri, 13 Jun 2025 16:24:12 +0100 Subject: [PATCH] fix: handle window.location mocking in CI environment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a more robust approach to mock window.location that works across different Jest environments. The previous approach failed in CI with "Cannot redefine property" error. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../__tests__/AuthDebugger.test.tsx | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/client/src/components/__tests__/AuthDebugger.test.tsx b/client/src/components/__tests__/AuthDebugger.test.tsx index 2130e68b..354e8037 100644 --- a/client/src/components/__tests__/AuthDebugger.test.tsx +++ b/client/src/components/__tests__/AuthDebugger.test.tsx @@ -84,11 +84,28 @@ Object.defineProperty(window, "sessionStorage", { value: sessionStorageMock, }); -Object.defineProperty(window, "location", { - value: { - origin: "http://localhost:3000", - }, -}); +// Mock window.location in a way that works in all environments +const mockLocation = { + origin: "http://localhost:3000", +}; + +// Try to delete first, then redefine +try { + delete (window as any).location; + window.location = mockLocation as any; +} catch { + // If that fails, try Object.defineProperty with configurable + try { + Object.defineProperty(window, "location", { + value: mockLocation, + writable: true, + configurable: true, + }); + } catch { + // As a last resort, just assign to window.location + (window as any).location = mockLocation; + } +} describe("AuthDebugger", () => { const defaultAuthState = EMPTY_DEBUGGER_STATE;