import { randomFillSync } from 'crypto' ; import { generateUID } from '../../src/utils/uid' ; test ( 'Unique identifier generation' , ( ) => { expect ( 'crypto' in globalThis ) . toEqual ( false ) ; const shim1 = jest . fn ( ) ; globalThis . crypto = { getRandomValues : ( buffer ) => { shim1 ( ) ; return randomFillSync ( buffer ) ; } , } as any ; const uid1 = generateUID ( ) ; expect ( /^[a-f0-9]{32}$/ . test ( uid1 ) ) . toEqual ( true ) ; expect ( shim1 ) . toHaveBeenCalled ( ) ; const shim2 = jest . fn ( ) ; globalThis . crypto = { randomUUID : ( ) => { shim2 ( ) ; return 'a19cc926-bf7f-4d5f-bf9c-202bc7a4c7c6' ; } , } as any ; expect ( generateUID ( ) ) . toEqual ( 'a19cc926bf7f4d5fbf9c202bc7a4c7c6' ) ; expect ( shim2 ) . toHaveBeenCalled ( ) ; delete globalThis . crypto ; } ) ;