@@ -5,91 +5,89 @@ const {
55 isCustomComponent
66} = require ( '../lib/utilities' ) ;
77
8- describe ( 'utilities' , ( ) => {
9- describe ( 'invertObject' , ( ) => {
10- it . each ( [ undefined , null , 'string' , 0 , 1 , ( ) => { } ] ) (
11- `throws an error if the first argument is %p` ,
12- input => {
13- expect ( ( ) => {
14- invertObject ( input ) ;
15- } ) . toThrow ( TypeError ) ;
16- }
17- ) ;
8+ describe ( 'invertObject' , ( ) => {
9+ it . each ( [ undefined , null , '' , 'test' , 0 , 1 , true , false , ( ) => { } ] ) (
10+ 'throws error for value: %p' ,
11+ value => {
12+ expect ( ( ) => {
13+ invertObject ( value ) ;
14+ } ) . toThrow ( TypeError ) ;
15+ }
16+ ) ;
1817
19- it ( 'swaps key with value' , ( ) => {
20- expect (
21- invertObject ( {
22- foo : 'bar' ,
23- baz : 'qux'
24- } )
25- ) . toEqual ( {
26- bar : 'foo' ,
27- qux : 'baz'
28- } ) ;
18+ it ( 'swaps key with value' , ( ) => {
19+ expect (
20+ invertObject ( {
21+ foo : 'bar' ,
22+ baz : 'qux'
23+ } )
24+ ) . toEqual ( {
25+ bar : 'foo' ,
26+ qux : 'baz'
2927 } ) ;
28+ } ) ;
3029
31- it ( 'swaps key with value if value is string' , ( ) => {
30+ it ( 'swaps key with value if value is string' , ( ) => {
31+ expect (
32+ invertObject ( {
33+ $ : 'dollar' ,
34+ _ : 'underscore' ,
35+ num : 1 ,
36+ u : undefined ,
37+ n : null
38+ } )
39+ ) . toEqual ( {
40+ dollar : '$' ,
41+ underscore : '_'
42+ } ) ;
43+ } ) ;
44+
45+ describe ( 'options' , ( ) => {
46+ it ( 'applies override if provided' , ( ) => {
3247 expect (
33- invertObject ( {
34- $ : 'dollar' ,
35- _ : 'underscore' ,
36- num : 1 ,
37- u : undefined ,
38- n : null
48+ invertObject ( { foo : 'bar' , baz : 'qux' } , key => {
49+ if ( key === 'foo' ) {
50+ return [ 'key' , 'value' ] ;
51+ }
3952 } )
40- ) . toEqual ( {
41- dollar : '$' ,
42- underscore : '_'
43- } ) ;
53+ ) . toEqual ( { key : 'value' , qux : 'baz' } ) ;
4454 } ) ;
4555
46- describe ( 'options' , ( ) => {
47- it ( 'applies override if provided' , ( ) => {
48- expect (
49- invertObject ( { foo : 'bar' , baz : 'qux' } , key => {
50- if ( key === 'foo' ) {
51- return [ 'key' , 'value' ] ;
52- }
53- } )
54- ) . toEqual ( { key : 'value' , qux : 'baz' } ) ;
55- } ) ;
56-
57- it ( 'does not apply override if invalid' , ( ) => {
58- expect (
59- invertObject ( { foo : 'bar' , baz : 'qux' } , key => {
60- if ( key === 'foo' ) {
61- return [ 'key' ] ;
62- } else if ( key === 'baz' ) {
63- return { key : 'value' } ;
64- }
65- } )
66- ) . toEqual ( { bar : 'foo' , qux : 'baz' } ) ;
67- } ) ;
56+ it ( 'does not apply override if invalid' , ( ) => {
57+ expect (
58+ invertObject ( { foo : 'bar' , baz : 'qux' } , key => {
59+ if ( key === 'foo' ) {
60+ return [ 'key' ] ;
61+ } else if ( key === 'baz' ) {
62+ return { key : 'value' } ;
63+ }
64+ } )
65+ ) . toEqual ( { bar : 'foo' , qux : 'baz' } ) ;
6866 } ) ;
6967 } ) ;
68+ } ) ;
7069
71- describe ( 'isCustomComponent' , ( ) => {
72- it ( 'returns true if the tag contains a hyphen and is not in the whitelist' , ( ) => {
73- expect ( isCustomComponent ( 'my-custom-element' ) ) . toBe ( true ) ;
74- } ) ;
70+ describe ( 'isCustomComponent' , ( ) => {
71+ it ( 'returns true if the tag contains a hyphen and is not in the whitelist' , ( ) => {
72+ expect ( isCustomComponent ( 'my-custom-element' ) ) . toBe ( true ) ;
73+ } ) ;
7574
76- it ( 'returns false if the tag is in the whitelist' , ( ) => {
77- expect ( isCustomComponent ( 'annotation-xml' ) ) . toBe ( false ) ;
78- expect ( isCustomComponent ( 'color-profile' ) ) . toBe ( false ) ;
79- expect ( isCustomComponent ( 'font-face' ) ) . toBe ( false ) ;
80- } ) ;
75+ it ( 'returns false if the tag is in the whitelist' , ( ) => {
76+ expect ( isCustomComponent ( 'annotation-xml' ) ) . toBe ( false ) ;
77+ expect ( isCustomComponent ( 'color-profile' ) ) . toBe ( false ) ;
78+ expect ( isCustomComponent ( 'font-face' ) ) . toBe ( false ) ;
79+ } ) ;
8180
82- it ( 'returns true if the props contains an `is` key' , ( ) => {
83- expect ( isCustomComponent ( 'button' , { is : 'custom-button' } ) ) . toBe ( true ) ;
84- } ) ;
81+ it ( 'returns true if the props contains an `is` key' , ( ) => {
82+ expect ( isCustomComponent ( 'button' , { is : 'custom-button' } ) ) . toBe ( true ) ;
8583 } ) ;
84+ } ) ;
8685
87- describe ( 'PRESERVE_CUSTOM_ATTRIBUTES' , ( ) => {
88- const isReactGreaterThan15 =
89- parseInt ( React . version . match ( / ^ \d ./ ) [ 0 ] , 10 ) >= 16 ;
86+ describe ( 'PRESERVE_CUSTOM_ATTRIBUTES' , ( ) => {
87+ const isReactGreaterThan15 =
88+ parseInt ( React . version . match ( / ^ \d ./ ) [ 0 ] , 10 ) >= 16 ;
9089
91- it ( `is ${ isReactGreaterThan15 } when React.version="${ React . version } "` , ( ) => {
92- expect ( PRESERVE_CUSTOM_ATTRIBUTES ) . toBe ( isReactGreaterThan15 ) ;
93- } ) ;
90+ it ( `is ${ isReactGreaterThan15 } when React.version="${ React . version } "` , ( ) => {
91+ expect ( PRESERVE_CUSTOM_ATTRIBUTES ) . toBe ( isReactGreaterThan15 ) ;
9492 } ) ;
9593} ) ;
0 commit comments