@@ -2,20 +2,44 @@ import { camelCaseKeys, fetchFlags, getFlattenedFlagsFromChangeset } from './uti
22import { LDClient , LDFlagChangeset , LDFlagSet } from 'launchdarkly-js-client-sdk' ;
33import { defaultReactOptions , LDReactOptions } from './types' ;
44
5+ const caseTestCases = [
6+ [ 'camelCase' , 'camelCase' ] ,
7+ [ 'PascalCase' , 'pascalCase' ] ,
8+ [ 'kebab-case' , 'kebabCase' ] ,
9+ [ 'SCREAMING-KEBAB-CASE' , 'screamingKebabCase' ] ,
10+ [ 'snake_case' , 'snakeCase' ] ,
11+ [ 'SCREAMING_SNAKE_CASE' , 'screamingSnakeCase' ] ,
12+ [ 'camel_Snake_Case' , 'camelSnakeCase' ] ,
13+ [ 'Pascal_Snake_Case' , 'pascalSnakeCase' ] ,
14+ [ 'Train-Case' , 'trainCase' ] ,
15+ // we can possibly drop support for these as they are unlikely used in practice
16+ [ 'snake_kebab-case' , 'snakeKebabCase' ] ,
17+ [ 'dragon.case' , 'dragonCase' ] ,
18+ [ 'SCREAMING.DRAGON.CASE' , 'screamingDragonCase' ] ,
19+ [ 'PascalDragon.Snake_Kebab-Case' , 'pascalDragonSnakeKebabCase' ] ,
20+ [ 'SCREAMING.DRAGON_SNAKE_KEBAB-CASE' , 'screamingDragonSnakeKebabCase' ] ,
21+ ] ;
22+
523describe ( 'Utils' , ( ) => {
6- test ( 'camelCaseKeys should ignore system keys' , ( ) => {
7- const bootstrap = {
8- 'test-flag' : true ,
9- 'another-test-flag' : false ,
10- $flagsState : {
11- 'test-flag' : { version : 125 , variation : 0 , trackEvents : true } ,
12- 'another-test-flag' : { version : 18 , variation : 1 } ,
13- } ,
14- $valid : true ,
15- } ;
24+ describe ( 'camelCaseKeys' , ( ) => {
25+ test ( 'should ignore system keys' , ( ) => {
26+ const bootstrap = {
27+ 'test-flag' : true ,
28+ 'another-test-flag' : false ,
29+ $flagsState : {
30+ 'test-flag' : { version : 125 , variation : 0 , trackEvents : true } ,
31+ 'another-test-flag' : { version : 18 , variation : 1 } ,
32+ } ,
33+ $valid : true ,
34+ } ;
1635
17- const result = camelCaseKeys ( bootstrap ) ;
18- expect ( result ) . toEqual ( { testFlag : true , anotherTestFlag : false } ) ;
36+ const result = camelCaseKeys ( bootstrap ) ;
37+ expect ( result ) . toEqual ( { testFlag : true , anotherTestFlag : false } ) ;
38+ } ) ;
39+
40+ test . each ( caseTestCases ) ( 'should handle %s' , ( key , camelKey ) => {
41+ expect ( camelCaseKeys ( { [ key ] : false } ) ) . toEqual ( { [ camelKey ] : false } ) ;
42+ } ) ;
1943 } ) ;
2044
2145 test ( 'getFlattenedFlagsFromChangeset should return current values of all flags when no targetFlags specified' , ( ) => {
0 commit comments