8000 fix: handle window.location mocking in CI environment · modelcontextprotocol/inspector@1d531d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1d531d5

Browse files
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>
1 parent ace1cf6 commit 1d531d5

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

client/src/components/__tests__/AuthDebugger.test.tsx

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,28 @@ Object.defineProperty(window, "sessionStorage", {
8484
value: sessionStorageMock,
8585
});
8686

87-
Object.defineProperty(window, "location", {
88-
value: {
89-
origin: "http://localhost:3000",
90-
},
91-
});
87+
// Mock window.location in a way that works in all environments
88+
const mockLocation = {
89+
origin: "http://localhost:3000",
90+
};
91+
92+
// Try to delete first, then redefine
93+
try {
94+
delete (window as any).location;
95+
window.location = mockLocation as any;
96+
} catch {
97+
// If that fails, try Object.defineProperty with configurable
98+
try {
99+
Object.defineProperty(window, "location", {
100+
value: mockLocation,
101+
writable: true,
102+
configurable: true,
103+
});
104+
} catch {
105+
// As a last resort, just assign to window.location
106+
(window as any).location = mockLocation;
107+
}
108+
}
92109

93110
describe("AuthDebugger", () => {
94111
const defaultAuthState = EMPTY_DEBUGGER_STATE;

0 commit comments

Comments
 (0)
0