diff --git a/__tests__/utils/helpers.test.ts b/__tests__/utils/helpers.test.ts index a5a1032..6cda80c 100644 --- a/__tests__/utils/helpers.test.ts +++ b/__tests__/utils/helpers.test.ts @@ -391,6 +391,43 @@ describe('ID Generation', () => { expect(typeof id).toBe('string'); expect(id.length).toBeGreaterThan(0); }); + + it('should use window.crypto when available', () => { + const id = generateId(); + expect(id).toBeDefined(); + expect(id.length).toBeGreaterThan(5); + }); + + it('should fallback to globalThis.crypto when window.crypto is unavailable', () => { + const originalWindow = global.window; + // @ts-ignore + delete global.window; + + const id = generateId(); + expect(id).toBeDefined(); + expect(typeof id).toBe('string'); + + global.window = originalWindow; + }); + + it('should fallback to timestamp when no crypto is available', () => { + const originalWindow = global.window; + const originalGlobalThis = global.globalThis; + const originalCrypto = globalThis.crypto; + + // @ts-ignore + delete global.window; + // @ts-ignore + delete globalThis.crypto; + + const id = generateId(); + expect(id).toBeDefined(); + expect(typeof id).toBe('string'); + expect(id.length).toBeGreaterThan(0); + + global.window = originalWindow; + globalThis.crypto = originalCrypto; + }); }); });