1
- const assert = require ( 'assert' ) ;
2
1
const React = require ( 'react' ) ;
3
2
const {
4
3
PRESERVE_CUSTOM_ATTRIBUTES ,
@@ -11,9 +10,9 @@ describe('utilities', () => {
11
10
describe ( 'camelCase' , ( ) => {
12
11
[ undefined , null , 1337 , { } , [ ] ] . forEach ( value => {
13
12
it ( `throws an error if first argument is ${ value } ` , ( ) => {
14
- assert . throws ( ( ) => {
13
+ expect ( ( ) => {
15
14
camelCase ( value ) ;
16
- } , TypeError ) ;
15
+ } ) . toThrow ( TypeError ) ;
17
16
} ) ;
18
17
} ) ;
19
18
@@ -26,7 +25,7 @@ describe('utilities', () => {
26
25
[ '--foo-bar' , '--foo-bar' ] ,
27
26
[ '--foo-100' , '--foo-100' ]
28
27
] . forEach ( testCase => {
29
- assert . strictEqual ( camelCase ( testCase [ 0 ] ) , testCase [ 1 ] ) ;
28
+ expect ( camelCase ( testCase [ 0 ] ) ) . toBe ( testCase [ 1 ] ) ;
30
29
} ) ;
31
30
} ) ;
32
31
@@ -36,86 +35,85 @@ describe('utilities', () => {
36
35
[ 'foo-bar-baz' , 'fooBarBaz' ] ,
37
36
[ 'CAMEL-CASE' , 'camelCase' ]
38
37
] . forEach ( testCase => {
39
- assert . strictEqual ( camelCase ( testCase [ 0 ] ) , testCase [ 1 ] ) ;
38
+ expect ( camelCase ( testCase [ 0 ] ) ) . toBe ( testCase [ 1 ] ) ;
40
39
} ) ;
41
40
} ) ;
42
41
} ) ;
43
42
44
43
describe ( 'invertObject' , ( ) => {
45
44
[ undefined , null , 'foo' , 1337 ] . forEach ( value => {
46
45
it ( `throws an error if the first argument is ${ value } ` , ( ) => {
47
- assert . throws ( ( ) => {
46
+ expect ( ( ) => {
48
47
invertObject ( value ) ;
49
- } , TypeError ) ;
48
+ } ) . toThrow ( TypeError ) ;
50
49
} ) ;
51
50
} ) ;
52
51
53
52
it ( 'swaps key with value' , ( ) => {
54
- assert . deepEqual ( invertObject ( { foo : 'bar' , baz : 'qux' } ) , {
53
+ expect (
54
+ invertObject ( {
55
+ foo : 'bar' ,
56
+ baz : 'qux'
57
+ } )
58
+ ) . toEqual ( {
55
59
bar : 'foo' ,
56
60
qux : 'baz'
57
61
} ) ;
58
62
} ) ;
59
63
60
64
it ( 'swaps key with value if value is string' , ( ) => {
61
- assert . deepEqual (
65
+ expect (
62
66
invertObject ( {
63
67
$ : 'dollar' ,
64
68
_ : 'underscore' ,
65
69
num : 1 ,
66
70
u : undefined ,
67
71
n : null
68
- } ) ,
69
- {
70
- dollar : '$' ,
71
- underscore : '_'
72
- }
73
- ) ;
72
+ } )
73
+ ) . toEqual ( {
74
+ dollar : '$' ,
75
+ underscore : '_'
76
+ } ) ;
74
77
} ) ;
75
78
76
79
describe ( 'options' , ( ) => {
77
80
it ( 'applies override if provided' , ( ) => {
78
- assert . deepEqual (
81
+ expect (
79
82
invertObject ( { foo : 'bar' , baz : 'qux' } , key => {
80
83
if ( key === 'foo' ) {
81
84
return [ 'key' , 'value' ] ;
82
85
}
83
- } ) ,
84
- { key : 'value' , qux : 'baz' }
85
- ) ;
86
+ } )
87
+ ) . toEqual ( { key : 'value' , qux : 'baz' } ) ;
86
88
} ) ;
87
89
88
90
it ( 'does not apply override if invalid' , ( ) => {
89
- assert . deepEqual (
91
+ expect (
90
92
invertObject ( { foo : 'bar' , baz : 'qux' } , key => {
91
93
if ( key === 'foo' ) {
92
94
return [ 'key' ] ;
93
95
} else if ( key === 'baz' ) {
94
96
return { key : 'value' } ;
95
97
}
96
- } ) ,
97
- { bar : 'foo' , qux : 'baz' }
98
- ) ;
98
+ } )
99
+ ) . toEqual ( { bar : 'foo' , qux : 'baz' } ) ;
99
100
} ) ;
100
101
} ) ;
101
102
} ) ;
102
103
103
104
describe ( 'isCustomComponent' , ( ) => {
104
105
it ( 'returns true if the tag contains a hyphen and is not in the whitelist' , ( ) => {
105
- assert . strictEqual ( isCustomComponent ( 'my-custom-element' ) , true ) ;
106
+ expect ( isCustomComponent ( 'my-custom-element' ) ) . toBe ( true ) ;
106
107
} ) ;
107
108
108
109
it ( 'returns false if the tag is in the whitelist' , ( ) => {
109
- assert . strictEqual ( isCustomComponent ( 'annotation-xml' ) , false ) ;
110
- assert . strictEqual ( isCustomComponent ( 'color-profile' ) , false ) ;
111
- assert . strictEqual ( isCustomComponent ( 'font-face' ) , false ) ;
110
+ expect ( isCustomComponent ( 'annotation-xml' ) ) . toBe ( false ) ;
111
+ expect ( isCustomComponent ( 'color-profile' ) ) . toBe ( false ) ;
112
+ expect ( isCustomComponent ( 'font-face' ) ) . toBe ( false ) ;
112
113
} ) ;
113
114
114
115
it ( 'returns true if the props contains an `is` key' , ( ) => {
115
- assert . strictEqual (
116
- isCustomComponent ( 'button' , { is : 'custom-button' } ) ,
117
- true
118
- ) ;
116
+ expect ( isCustomComponent ( 'button' , { is : 'custom-button' } ) ) . toBe ( true ) ;
119
117
} ) ;
120
118
} ) ;
121
119
@@ -124,7 +122,7 @@ describe('utilities', () => {
124
122
parseInt ( React . version . match ( / ^ \d ./ ) [ 0 ] , 10 ) >= 16 ;
125
123
126
124
it ( `is ${ isReactGreaterThan15 } when React.version="${ React . version } "` , ( ) => {
127
- assert . strictEqual ( PRESERVE_CUSTOM_ATTRIBUTES , isReactGreaterThan15 ) ;
125
+ expect ( PRESERVE_CUSTOM_ATTRIBUTES ) . toBe ( isReactGreaterThan15 ) ;
128
126
} ) ;
129
127
} ) ;
130
128
} ) ;
0 commit comments