Skip to content

Commit 6e74b50

Browse files
test(attributes-to-props): refactor to expect instead of assert
1 parent 9f4a9fd commit 6e74b50

File tree

1 file changed

+118
-136
lines changed

1 file changed

+118
-136
lines changed

test/attributes-to-props.test.js

Lines changed: 118 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,128 @@
1-
const assert = require('assert');
21
const attributesToProps = require('../lib/attributes-to-props');
32
const utilities = require('../lib/utilities');
43

54
describe('attributes to props', () => {
65
describe('HTML', () => {
76
it('converts attributes to React props', () => {
8-
assert.deepEqual(
7+
expect(
98
attributesToProps({
109
class: 'ic',
1110
for: 'tran',
1211
'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+
});
2018
});
2119

2220
it('converts standard attributes to React props', () => {
23-
assert.deepEqual(
21+
expect(
2422
attributesToProps({
2523
allowfullscreen: true,
2624
charset: 'utf-8',
2725
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+
});
3532
});
3633

3734
it('converts RDFa attributes to React props', () => {
38-
assert.deepEqual(
35+
expect(
3936
attributesToProps({
4037
property: 'foo',
4138
typeof: 'bar'
42-
}),
43-
{
44-
property: 'foo',
45-
typeof: 'bar'
46-
}
47-
);
39+
})
40+
).toEqual({
41+
property: 'foo',
42+
typeof: 'bar'
43+
});
4844
});
4945

5046
it('converts non-standard attributes to React props', () => {
51-
assert.deepEqual(
47+
expect(
5248
attributesToProps({
5349
itemscope: true,
5450
itemid: 1337
55-
}),
56-
{
57-
itemScope: true,
58-
itemID: 1337
59-
}
60-
);
51+
})
52+
).toEqual({
53+
itemScope: true,
54+
itemID: 1337
55+
});
6156
});
6257

6358
it('keeps `data-*` and `aria-*` attributes as is', () => {
64-
assert.deepEqual(
59+
expect(
6560
attributesToProps({
6661
'data-foo': 'bar',
6762
'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+
});
7468
});
7569

7670
it('converts attributes with weird capitalization', () => {
77-
assert.deepEqual(
71+
expect(
7872
attributesToProps({
7973
'ACCEPT-CHARSET': 'ISO-8859-1',
8074
formNOvalidate: true,
8175
sEcUrItY: 'restricted',
8276
'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+
});
9184
});
9285

9386
it('converts boolean attributes', () => {
94-
assert.deepEqual(
87+
expect(
9588
attributesToProps({
9689
readonly: ''
97-
}),
98-
{
99-
readOnly: true
100-
}
101-
);
90+
})
91+
).toEqual({
92+
readOnly: true
93+
});
10294

103-
assert.deepEqual(
95+
expect(
10496
attributesToProps({
10597
disabled: 'disabled'
106-
}),
107-
{
108-
disabled: true
109-
}
110-
);
98+
})
99+
).toEqual({
100+
disabled: true
101+
});
111102
});
112103

113104
it('converts overloaded boolean attributes', () => {
114-
assert.deepEqual(
105+
expect(
115106
attributesToProps({
116107
download: ''
117-
}),
118-
{
119-
download: true
120-
}
121-
);
108+
})
109+
).toEqual({
110+
download: true
111+
});
122112

123-
assert.deepEqual(
113+
expect(
124114
attributesToProps({
125115
download: 'filename'
126-
}),
127-
{
128-
download: 'filename'
129-
}
130-
);
116+
})
117+
).toEqual({
118+
download: 'filename'
119+
});
131120
});
132121
});
133122

134123
describe('SVG', () => {
135124
it('converts attributes to React props', () => {
136-
assert.deepEqual(
125+
expect(
137126
attributesToProps({
138127
edgeMode: 'edgeMode',
139128
'fill-opacity': '0.42',
@@ -142,97 +131,91 @@ describe('attributes to props', () => {
142131
'horiz-adv-x': '9001',
143132
stroke: 'none',
144133
'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+
});
156144
});
157145

158146
it('keeps incorrectly capitalized attributes', () => {
159-
assert.deepEqual(
147+
expect(
160148
attributesToProps({
161149
'XLINK:HREF': '#',
162150
YChannelSelector: 'G',
163151
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+
});
171158
});
172159
});
173160

174161
// cssToJs
175162
describe('style', () => {
176163
it('parses empty inline style to object', () => {
177-
assert.deepEqual(attributesToProps({ style: '' }), { style: {} });
164+
expect(attributesToProps({ style: '' })).toEqual({ style: {} });
178165
});
179166

180167
it('does not parse CSS comment', () => {
181-
assert.deepEqual(attributesToProps({ style: '/* comment */' }), {
168+
expect(attributesToProps({ style: '/* comment */' })).toEqual({
182169
style: {}
183170
});
184171
});
185172

186173
it('parses inline style to object', () => {
187-
assert.deepEqual(
174+
expect(
188175
attributesToProps({
189176
style:
190177
'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)'
201187
}
202-
);
188+
});
203189

204-
assert.deepEqual(
190+
expect(
205191
attributesToProps({
206192
style:
207193
'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'
216201
}
217-
);
202+
});
218203

219-
assert.deepEqual(
204+
expect(
220205
attributesToProps({
221206
style: null
222-
}),
223-
{
224-
style: null
225-
}
226-
);
207+
})
208+
).toEqual({
209+
style: null
210+
});
227211

228-
assert.deepEqual(
212+
expect(
229213
attributesToProps({
230214
style: undefined
231-
}),
232-
{
233-
style: undefined
234-
}
235-
);
215+
})
216+
).toEqual({
217+
style: undefined
218+
});
236219
});
237220
});
238221

@@ -253,7 +236,8 @@ describe('attributes to props', () => {
253236
toString: '',
254237
valueOf: ''
255238
};
256-
assert.deepEqual(attributesToProps(attributes), attributes);
239+
240+
expect(attributesToProps(attributes)).toEqual(attributes);
257241
});
258242

259243
describe('when utilties.PRESERVE_CUSTOM_ATTRIBUTES=false', () => {
@@ -268,23 +252,21 @@ describe('attributes to props', () => {
268252
});
269253

270254
it('omits unknown attributes', () => {
271-
assert.deepEqual(
255+
expect(
272256
attributesToProps({
273257
unknownAttribute: 'someValue'
274-
}),
275-
{}
276-
);
258+
})
259+
).toEqual({});
277260
});
278261

279262
it('omits incorrectly capitalized attributes', () => {
280-
assert.deepEqual(
263+
expect(
281264
attributesToProps({
282265
'XLINK:HREF': '#',
283266
YChannelSelector: 'G',
284267
ZoomAndPan: 'disable'
285-
}),
286-
{}
287-
);
268+
})
269+
).toEqual({});
288270
});
289271
});
290272
});

0 commit comments

Comments
 (0)