Skip to content

Commit f2f9a8d

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 10ab2b8 commit f2f9a8d

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,5 +1,5 @@
11
/* eslint-disable no-bitwise */
2-
import { fallbackUuidV4, formatDataAsUuidV4 } from '../../src/platform/randomUuidV4';
2+
import randomUuidV4, { fallbackUuidV4, formatDataAsUuidV4 } from '../../src/platform/randomUuidV4';
33

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

0 commit comments

Comments
 (0)