File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed
projects/igniteui-angular/src/lib/grids/common Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 1+ import { getUUID } from './random' ;
2+
3+ describe ( 'Random (crypto.randomUuid()) fallback unit tests' , ( ) => {
4+ let originalRandomUuid = crypto . randomUUID ;
5+
6+ beforeAll ( ( ) => {
7+ crypto . randomUUID = null ; // Mock crypto.randomUUID to simulate a non-secure context
8+ } ) ;
9+
10+ it ( 'should generate a valid UUID' , ( ) => {
11+ const uuid = getUUID ( ) ;
12+ expect ( uuid ) . toMatch ( / ^ [ 0 - 9 a - f ] { 8 } - [ 0 - 9 a - f ] { 4 } - 4 [ 0 - 9 a - f ] { 3 } - [ 8 9 a b ] [ 0 - 9 a - f ] { 3 } - [ 0 - 9 a - f ] { 12 } $ / ) ;
13+ } ) ;
14+
15+ it ( 'should generate unique UUIDs' , ( ) => {
16+ const uuids = new Set ( ) ;
17+ for ( let i = 0 ; i < 100 ; i ++ ) {
18+ uuids . add ( getUUID ( ) ) ;
19+ }
20+ expect ( uuids . size ) . toBe ( 100 ) ; // All UUIDs should be unique
21+ } ) ;
22+
23+ afterAll ( ( ) => {
24+ crypto . randomUUID = originalRandomUuid ; // Restore the original function
25+ } ) ;
26+ } ) ;
You can’t perform that action at this time.
0 commit comments