Skip to content

Commit 0869f9d

Browse files
joker23claude
andcommitted
test: add unit tests for typeof fix
- BrowserApi: verify isDocument() and isWindow() return true when globals exist - randomUuidV4: verify fallback path when crypto.randomUUID is unavailable Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 28c8587 commit 0869f9d

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { isDocument, isWindow } from '../src/BrowserApi';
2+
3+
it('isDocument returns true when document is defined', () => {
4+
expect(isDocument()).toBe(true);
5+
});
6+
7+
it('isWindow returns true when window is defined', () => {
8+
expect(isWindow()).toBe(true);
9+
});

packages/sdk/browser/__tests__/platform/randomUuidV4.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fallbackUuidV4, formatDataAsUuidV4 } from '../../src/platform/randomUuidV4';
1+
import randomUuidV4, { fallbackUuidV4, formatDataAsUuidV4 } from '../../src/platform/randomUuidV4';
22

33
it('formats conformant UUID', () => {
44
// For this test we remove the random component and just inspect the variant and version.
@@ -26,3 +26,19 @@ it('formats conformant UUID', () => {
2626
expect(specifierB).toEqual(0x8);
2727
expect(specifierC).toEqual(0x8);
2828
});
29+
30+
it('falls back when crypto.randomUUID is unavailable', () => {
31+
const original = globalThis.crypto;
32+
Object.defineProperty(globalThis, 'crypto', {
33+
value: { getRandomValues: original.getRandomValues.bind(original) },
34+
configurable: true,
35+
});
36+
37+
try {
38+
const uuid = randomUuidV4();
39+
expect(uuid).toHaveLength(36);
40+
expect(uuid[14]).toEqual('4');
41+
} finally {
42+
Object.defineProperty(globalThis, 'crypto', { value: original, configurable: true });
43+
}
44+
});

0 commit comments

Comments
 (0)