Skip to content

Commit 7cc1435

Browse files
joker23claude
andcommitted
test: add negative tests for isDocument and isWindow
Verify isDocument() and isWindow() return false when the globals are undefined, simulating a service worker environment. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f2f9a8d commit 7cc1435

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

packages/sdk/browser/__tests__/BrowserApi.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ it('isDocument returns true when document is defined', () => {
44
expect(isDocument()).toBe(true);
55
});
66

7+
it('isDocument returns false when document is not defined', () => {
8+
const original = Object.getOwnPropertyDescriptor(globalThis, 'document');
9+
Object.defineProperty(globalThis, 'document', { value: undefined, configurable: true });
10+
try {
11+
expect(isDocument()).toBe(false);
12+
} finally {
13+
Object.defineProperty(globalThis, 'document', original!);
14+
}
15+
});
16+
717
it('isWindow returns true when window is defined', () => {
818
expect(isWindow()).toBe(true);
919
});
20+
21+
it('isWindow returns false when window is not defined', () => {
22+
const original = Object.getOwnPropertyDescriptor(globalThis, 'window');
23+
Object.defineProperty(globalThis, 'window', { value: undefined, configurable: true });
24+
try {
25+
expect(isWindow()).toBe(false);
26+
} finally {
27+
Object.defineProperty(globalThis, 'window', original!);
28+
}
29+
});

0 commit comments

Comments
 (0)