1
- const assert = require ( 'assert' ) ;
2
1
const attributesToProps = require ( '../lib/attributes-to-props' ) ;
3
2
const utilities = require ( '../lib/utilities' ) ;
4
3
5
4
describe ( 'attributes to props' , ( ) => {
6
5
describe ( 'HTML' , ( ) => {
7
6
it ( 'converts attributes to React props' , ( ) => {
8
- assert . deepEqual (
7
+ expect (
9
8
attributesToProps ( {
10
9
class : 'ic' ,
11
10
for : 'tran' ,
12
11
'http-equiv' : 'refresh'
13
- } ) ,
14
- {
15
- className : 'ic' ,
16
- htmlFor : 'tran' ,
17
- httpEquiv : 'refresh'
18
- }
19
- ) ;
12
+ } )
13
+ ) . toEqual ( {
14
+ className : 'ic' ,
15
+ htmlFor : 'tran' ,
16
+ httpEquiv : 'refresh'
17
+ } ) ;
20
18
} ) ;
21
19
22
20
it ( 'converts standard attributes to React props' , ( ) => {
23
- assert . deepEqual (
21
+ expect (
24
22
attributesToProps ( {
25
23
allowfullscreen : true ,
26
24
charset : 'utf-8' ,
27
25
tabindex : 1
28
- } ) ,
29
- {
30
- allowFullScreen : true ,
31
- charSet : 'utf-8' ,
32
- tabIndex : 1
33
- }
34
- ) ;
26
+ } )
27
+ ) . toEqual ( {
28
+ allowFullScreen : true ,
29
+ charSet : 'utf-8' ,
30
+ tabIndex : 1
31
+ } ) ;
35
32
} ) ;
36
33
37
34
it ( 'converts RDFa attributes to React props' , ( ) => {
38
- assert . deepEqual (
35
+ expect (
39
36
attributesToProps ( {
40
37
property : 'foo' ,
41
38
typeof : 'bar'
42
- } ) ,
43
- {
44
- property : 'foo' ,
45
- typeof : 'bar'
46
- }
47
- ) ;
39
+ } )
40
+ ) . toEqual ( {
41
+ property : 'foo' ,
42
+ typeof : 'bar'
43
+ } ) ;
48
44
} ) ;
49
45
50
46
it ( 'converts non-standard attributes to React props' , ( ) => {
51
- assert . deepEqual (
47
+ expect (
52
48
attributesToProps ( {
53
49
itemscope : true ,
54
50
itemid : 1337
55
- } ) ,
56
- {
57
- itemScope : true ,
58
- itemID : 1337
59
- }
60
- ) ;
51
+ } )
52
+ ) . toEqual ( {
53
+ itemScope : true ,
54
+ itemID : 1337
55
+ } ) ;
61
56
} ) ;
62
57
63
58
it ( 'keeps `data-*` and `aria-*` attributes as is' , ( ) => {
64
- assert . deepEqual (
59
+ expect (
65
60
attributesToProps ( {
66
61
'data-foo' : 'bar' ,
67
62
'aria-live' : 'polite'
68
- } ) ,
69
- {
70
- 'data-foo' : 'bar' ,
71
- 'aria-live' : 'polite'
72
- }
73
- ) ;
63
+ } )
64
+ ) . toEqual ( {
65
+ 'data-foo' : 'bar' ,
66
+ 'aria-live' : 'polite'
67
+ } ) ;
74
68
} ) ;
75
69
76
70
it ( 'converts attributes with weird capitalization' , ( ) => {
77
- assert . deepEqual (
71
+ expect (
78
72
attributesToProps ( {
79
73
'ACCEPT-CHARSET' : 'ISO-8859-1' ,
80
74
formNOvalidate : true ,
81
75
sEcUrItY : 'restricted' ,
82
76
'data-FOO' : 'bar'
83
- } ) ,
84
- {
85
- acceptCharset : 'ISO-8859-1' ,
86
- formNoValidate : true ,
87
- security : 'restricted' ,
88
- 'data-FOO' : 'bar'
89
- }
90
- ) ;
77
+ } )
78
+ ) . toEqual ( {
79
+ acceptCharset : 'ISO-8859-1' ,
80
+ formNoValidate : true ,
81
+ security : 'restricted' ,
82
+ 'data-FOO' : 'bar'
83
+ } ) ;
91
84
} ) ;
92
85
93
86
it ( 'converts boolean attributes' , ( ) => {
94
- assert . deepEqual (
87
+ expect (
95
88
attributesToProps ( {
96
89
readonly : ''
97
- } ) ,
98
- {
99
- readOnly : true
100
- }
101
- ) ;
90
+ } )
91
+ ) . toEqual ( {
92
+ readOnly : true
93
+ } ) ;
102
94
103
- assert . deepEqual (
95
+ expect (
104
96
attributesToProps ( {
105
97
disabled : 'disabled'
106
- } ) ,
107
- {
108
- disabled : true
109
- }
110
- ) ;
98
+ } )
99
+ ) . toEqual ( {
100
+ disabled : true
101
+ } ) ;
111
102
} ) ;
112
103
113
104
it ( 'converts overloaded boolean attributes' , ( ) => {
114
- assert . deepEqual (
105
+ expect (
115
106
attributesToProps ( {
116
107
download : ''
117
- } ) ,
118
- {
119
- download : true
120
- }
121
- ) ;
108
+ } )
109
+ ) . toEqual ( {
110
+ download : true
111
+ } ) ;
122
112
123
- assert . deepEqual (
113
+ expect (
124
114
attributesToProps ( {
125
115
download : 'filename'
126
- } ) ,
127
- {
128
- download : 'filename'
129
- }
130
- ) ;
116
+ } )
117
+ ) . toEqual ( {
118
+ download : 'filename'
119
+ } ) ;
131
120
} ) ;
132
121
} ) ;
133
122
134
123
describe ( 'SVG' , ( ) => {
135
124
it ( 'converts attributes to React props' , ( ) => {
136
- assert . deepEqual (
125
+ expect (
137
126
attributesToProps ( {
138
127
edgeMode : 'edgeMode' ,
139
128
'fill-opacity' : '0.42' ,
@@ -142,97 +131,91 @@ describe('attributes to props', () => {
142
131
'horiz-adv-x' : '9001' ,
143
132
stroke : 'none' ,
144
133
'xml:base' : 'http://example.org'
145
- } ) ,
146
- {
147
- edgeMode : 'edgeMode' ,
148
- fillOpacity : '0.42' ,
149
- fillRule : 'evenodd' ,
150
- glyphOrientationVertical : 'auto' ,
151
- horizAdvX : '9001' ,
152
- stroke : 'none' ,
153
- xmlBase : 'http://example.org'
154
- }
155
- ) ;
134
+ } )
135
+ ) . toEqual ( {
136
+ edgeMode : 'edgeMode' ,
137
+ fillOpacity : '0.42' ,
138
+ fillRule : 'evenodd' ,
139
+ glyphOrientationVertical : 'auto' ,
140
+ horizAdvX : '9001' ,
141
+ stroke : 'none' ,
142
+ xmlBase : 'http://example.org'
143
+ } ) ;
156
144
} ) ;
157
145
158
146
it ( 'keeps incorrectly capitalized attributes' , ( ) => {
159
- assert . deepEqual (
147
+ expect (
160
148
attributesToProps ( {
161
149
'XLINK:HREF' : '#' ,
162
150
YChannelSelector : 'G' ,
163
151
ZoomAndPan : 'disable'
164
- } ) ,
165
- {
166
- 'XLINK:HREF' : '#' ,
167
- YChannelSelector : 'G' ,
168
- ZoomAndPan : 'disable'
169
- }
170
- ) ;
152
+ } )
153
+ ) . toEqual ( {
154
+ 'XLINK:HREF' : '#' ,
155
+ YChannelSelector : 'G' ,
156
+ ZoomAndPan : 'disable'
157
+ } ) ;
171
158
} ) ;
172
159
} ) ;
173
160
174
161
// cssToJs
175
162
describe ( 'style' , ( ) => {
176
163
it ( 'parses empty inline style to object' , ( ) => {
177
- assert . deepEqual ( attributesToProps ( { style : '' } ) , { style : { } } ) ;
164
+ expect ( attributesToProps ( { style : '' } ) ) . toEqual ( { style : { } } ) ;
178
165
} ) ;
179
166
180
167
it ( 'does not parse CSS comment' , ( ) => {
181
- assert . deepEqual ( attributesToProps ( { style : '/* comment */' } ) , {
168
+ expect ( attributesToProps ( { style : '/* comment */' } ) ) . toEqual ( {
182
169
style : { }
183
170
} ) ;
184
171
} ) ;
185
172
186
173
it ( 'parses inline style to object' , ( ) => {
187
- assert . deepEqual (
174
+ expect (
188
175
attributesToProps ( {
189
176
style :
190
177
'color: #f00; font-size: 42px; z-index: -1; -moz-border-radius-topright: 10px; background: url(data:image/png; base64,ivborw0kggoaaaansaaaabgdbtueaalgpc/xhbqaaaafzmuexurczmzpf399fx1+bm5mzy9avzxbesmgces5/p8/t9furvcrmu73jwlzosgsiizurcjo/ad+eqjjb4hv8bft+idpqocx1wjosbfhh2xssxeiyn3uli/6mnree07uiwjev8u8czwyuqdlkpg1bkb4nnm+veanfhqn1k4+gpt6ugqcvu2h2ovuif)'
191
- } ) ,
192
- {
193
- style : {
194
- color : '#f00' ,
195
- fontSize : '42px' ,
196
- zIndex : '-1' ,
197
- MozBorderRadiusTopright : '10px' ,
198
- background :
199
- 'url(data:image/png; base64,ivborw0kggoaaaansaaaabgdbtueaalgpc/xhbqaaaafzmuexurczmzpf399fx1+bm5mzy9avzxbesmgces5/p8/t9furvcrmu73jwlzosgsiizurcjo/ad+eqjjb4hv8bft+idpqocx1wjosbfhh2xssxeiyn3uli/6mnree07uiwjev8u8czwyuqdlkpg1bkb4nnm+veanfhqn1k4+gpt6ugqcvu2h2ovuif)'
200
- }
178
+ } )
179
+ ) . toEqual ( {
180
+ style : {
181
+ color : '#f00' ,
182
+ fontSize : '42px' ,
183
+ zIndex : '-1' ,
184
+ MozBorderRadiusTopright : '10px' ,
185
+ background :
186
+ 'url(data:image/png; base64,ivborw0kggoaaaansaaaabgdbtueaalgpc/xhbqaaaafzmuexurczmzpf399fx1+bm5mzy9avzxbesmgces5/p8/t9furvcrmu73jwlzosgsiizurcjo/ad+eqjjb4hv8bft+idpqocx1wjosbfhh2xssxeiyn3uli/6mnree07uiwjev8u8czwyuqdlkpg1bkb4nnm+veanfhqn1k4+gpt6ugqcvu2h2ovuif)'
201
187
}
202
- ) ;
188
+ } ) ;
203
189
204
- assert . deepEqual (
190
+ expect (
205
191
attributesToProps ( {
206
192
style :
207
193
'border-bottom-left-radius:1em;border-right-style:solid;Z-Index:-1;-moz-border-radius-bottomleft:20px'
208
- } ) ,
209
- {
210
- style : {
211
- borderBottomLeftRadius : '1em' ,
212
- borderRightStyle : 'solid' ,
213
- zIndex : '-1' ,
214
- MozBorderRadiusBottomleft : '20px'
215
- }
194
+ } )
195
+ ) . toEqual ( {
196
+ style : {
197
+ borderBottomLeftRadius : '1em' ,
198
+ borderRightStyle : 'solid' ,
199
+ zIndex : '-1' ,
200
+ MozBorderRadiusBottomleft : '20px'
216
201
}
217
- ) ;
202
+ } ) ;
218
203
219
- assert . deepEqual (
204
+ expect (
220
205
attributesToProps ( {
221
206
style : null
222
- } ) ,
223
- {
224
- style : null
225
- }
226
- ) ;
207
+ } )
208
+ ) . toEqual ( {
209
+ style : null
210
+ } ) ;
227
211
228
- assert . deepEqual (
212
+ expect (
229
213
attributesToProps ( {
230
214
style : undefined
231
- } ) ,
232
- {
233
- style : undefined
234
- }
235
- ) ;
215
+ } )
216
+ ) . toEqual ( {
217
+ style : undefined
218
+ } ) ;
236
219
} ) ;
237
220
} ) ;
238
221
@@ -253,7 +236,8 @@ describe('attributes to props', () => {
253
236
toString : '' ,
254
237
valueOf : ''
255
238
} ;
256
- assert . deepEqual ( attributesToProps ( attributes ) , attributes ) ;
239
+
240
+ expect ( attributesToProps ( attributes ) ) . toEqual ( attributes ) ;
257
241
} ) ;
258
242
259
243
describe ( 'when utilties.PRESERVE_CUSTOM_ATTRIBUTES=false' , ( ) => {
@@ -268,23 +252,21 @@ describe('attributes to props', () => {
268
252
} ) ;
269
253
270
254
it ( 'omits unknown attributes' , ( ) => {
271
- assert . deepEqual (
255
+ expect (
272
256
attributesToProps ( {
273
257
unknownAttribute : 'someValue'
274
- } ) ,
275
- { }
276
- ) ;
258
+ } )
259
+ ) . toEqual ( { } ) ;
277
260
} ) ;
278
261
279
262
it ( 'omits incorrectly capitalized attributes' , ( ) => {
280
- assert . deepEqual (
263
+ expect (
281
264
attributesToProps ( {
282
265
'XLINK:HREF' : '#' ,
283
266
YChannelSelector : 'G' ,
284
267
ZoomAndPan : 'disable'
285
- } ) ,
286
- { }
287
- ) ;
268
+ } )
269
+ ) . toEqual ( { } ) ;
288
270
} ) ;
289
271
} ) ;
290
272
} ) ;
0 commit comments