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:
parent
ace1cf642a
commit
1d531d5a36
1 changed files with 22 additions and 5 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in a new issue