fix: handle window.location mocking in CI environment

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 <noreply@anthropic.com>
This commit is contained in:
Jerome 2025-06-13 16:24:12 +01:00
commit 1d531d5a36
No known key found for this signature in database

View file

@ -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;