Skip to content

Commit ef04eff

Browse files
test: tidy tests, replace assert.equal with assert.strictEqual
1 parent d299826 commit ef04eff

File tree

3 files changed

+110
-106
lines changed

3 files changed

+110
-106
lines changed

test/dom-to-react.js

+2-11
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,7 @@ const domToReact = require('../lib/dom-to-react');
66
const { data, render } = require('./helpers/');
77
const utilities = require('../lib/utilities');
88

9-
describe('dom-to-react parser', () => {
10-
let actualReactVersion;
11-
beforeEach(() => {
12-
actualReactVersion = React.version;
13-
});
14-
15-
afterEach(() => {
16-
React.version = actualReactVersion;
17-
});
18-
9+
describe('dom-to-react', () => {
1910
it('converts single DOM node to React', () => {
2011
const html = data.html.single;
2112
const reactElement = domToReact(htmlToDOM(html));
@@ -39,7 +30,7 @@ describe('dom-to-react parser', () => {
3930
]);
4031
});
4132

42-
// https://facebook.github.io/react/docs/forms.html#why-textarea-value
33+
// https://reactjs.org/docs/forms.html#the-textarea-tag
4334
it('converts <textarea> correctly', () => {
4435
const html = data.html.textarea;
4536
const reactElement = domToReact(htmlToDOM(html));

test/html-to-react.js

+11-11
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@ describe('html-to-react', () => {
1818
});
1919

2020
it('returns string if it cannot be parsed as HTML', () => {
21-
assert.equal(parse('foo'), 'foo');
21+
assert.strictEqual(parse('foo'), 'foo');
2222
});
2323

2424
it('converts single HTML element to React', () => {
2525
const html = data.html.single;
2626
const reactElement = parse(html);
27-
assert.equal(render(reactElement), html);
27+
assert.strictEqual(render(reactElement), html);
2828
});
2929

3030
it('converts single HTML element and ignores comment', () => {
3131
const html = data.html.single;
3232
// comment should be ignored
3333
const reactElement = parse(html + data.html.comment);
34-
assert.equal(render(reactElement), html);
34+
assert.strictEqual(render(reactElement), html);
3535
});
3636

3737
it('converts multiple HTML elements to React', () => {
3838
const html = data.html.multiple;
3939
const reactElements = parse(html);
40-
assert.equal(
40+
assert.strictEqual(
4141
render(React.createElement('div', {}, reactElements)),
4242
'<div>' + html + '</div>'
4343
);
@@ -46,32 +46,32 @@ describe('html-to-react', () => {
4646
it('converts complex HTML to React', () => {
4747
const html = data.html.complex;
4848
const reactElement = parse(data.html.doctype + html);
49-
assert.equal(render(reactElement), html);
49+
assert.strictEqual(render(reactElement), html);
5050
});
5151

5252
it('converts empty <script> to React', () => {
5353
const html = '<script></script>';
5454
const reactElement = parse(html);
55-
assert.equal(render(reactElement), html);
55+
assert.strictEqual(render(reactElement), html);
5656
});
5757

5858
it('converts empty <style> to React', () => {
5959
const html = '<style></style>';
6060
const reactElement = parse(html);
61-
assert.equal(render(reactElement), html);
61+
assert.strictEqual(render(reactElement), html);
6262
});
6363

6464
it('converts SVG to React', () => {
6565
const svg = data.svg.complex;
6666
const reactElement = parse(svg);
67-
assert.equal(render(reactElement), svg);
67+
assert.strictEqual(render(reactElement), svg);
6868
});
6969

7070
it('decodes HTML entities', () => {
7171
const encodedEntities = 'asdf &amp; &yuml; &uuml; &apos;';
7272
const decodedEntities = "asdf & ÿ ü '";
7373
const reactElement = parse('<i>' + encodedEntities + '</i>');
74-
assert.equal(reactElement.props.children, decodedEntities);
74+
assert.strictEqual(reactElement.props.children, decodedEntities);
7575
});
7676
});
7777

@@ -86,7 +86,7 @@ describe('html-to-react', () => {
8686
}
8787
}
8888
});
89-
assert.equal(
89+
assert.strictEqual(
9090
render(reactElement),
9191
html.replace('<title>Title</title>', '<title>Replaced Title</title>')
9292
);
@@ -118,6 +118,6 @@ describe('html-to-react', () => {
118118

119119
describe('dom-to-react', () => {
120120
it('exports domToReact', () => {
121-
assert.equal(parse.domToReact, require('../lib/dom-to-react'));
121+
assert.strictEqual(parse.domToReact, require('../lib/dom-to-react'));
122122
});
123123
});

test/utilities.js

+97-84
Original file line numberDiff line numberDiff line change
@@ -7,111 +7,124 @@ const {
77
isCustomComponent
88
} = require('../lib/utilities');
99

10-
describe('utilties.camelCase', () => {
11-
[undefined, null, 1337, {}, []].forEach(value => {
12-
it(`throws an error if first argument is ${value}`, () => {
13-
assert.throws(() => {
14-
camelCase(value);
15-
}, TypeError);
10+
describe('utilities', () => {
11+
describe('camelCase', () => {
12+
[undefined, null, 1337, {}, []].forEach(value => {
13+
it(`throws an error if first argument is ${value}`, () => {
14+
assert.throws(() => {
15+
camelCase(value);
16+
}, TypeError);
17+
});
1618
});
17-
});
18-
19-
it('does not modify string if it does not need to be camelCased', () => {
20-
assert.equal(camelCase(''), '');
21-
assert.equal(camelCase('foo'), 'foo');
22-
assert.equal(camelCase('fooBar'), 'fooBar');
23-
assert.equal(camelCase('--fooBar'), '--fooBar');
24-
assert.equal(camelCase('--foo-bar'), '--foo-bar');
25-
assert.equal(camelCase('--foo100'), '--foo100');
26-
assert.equal(camelCase('--foo-100'), '--foo-100');
27-
});
2819

29-
it('camelCases a string', () => {
30-
assert.equal(camelCase('foo-bar'), 'fooBar');
31-
assert.equal(camelCase('foo-bar-baz'), 'fooBarBaz');
32-
assert.equal(camelCase('CAMEL-CASE'), 'camelCase');
33-
});
34-
});
20+
it('does not modify string if it does not need to be camelCased', () => {
21+
[
22+
['', ''],
23+
['foo', 'foo'],
24+
['fooBar', 'fooBar'],
25+
['--fooBar', '--fooBar'],
26+
['--foo-bar', '--foo-bar'],
27+
['--foo-100', '--foo-100']
28+
].forEach(testCase => {
29+
assert.strictEqual(camelCase(testCase[0]), testCase[1]);
30+
});
31+
});
3532

36-
describe('utilities.invertObject', () => {
37-
[undefined, null, 'foo', 1337].forEach(value => {
38-
it(`throws an error if the first argument is ${value}`, () => {
39-
assert.throws(() => {
40-
invertObject(value);
41-
}, TypeError);
33+
it('camelCases a string', () => {
34+
[
35+
['foo-bar', 'fooBar'],
36+
['foo-bar-baz', 'fooBarBaz'],
37+
['CAMEL-CASE', 'camelCase']
38+
].forEach(testCase => {
39+
assert.strictEqual(camelCase(testCase[0]), testCase[1]);
40+
});
4241
});
4342
});
4443

45-
it('swaps key with value', () => {
46-
assert.deepEqual(invertObject({ foo: 'bar', baz: 'qux' }), {
47-
bar: 'foo',
48-
qux: 'baz'
44+
describe('invertObject', () => {
45+
[undefined, null, 'foo', 1337].forEach(value => {
46+
it(`throws an error if the first argument is ${value}`, () => {
47+
assert.throws(() => {
48+
invertObject(value);
49+
}, TypeError);
50+
});
4951
});
50-
});
5152

52-
it('swaps key with value if value is string', () => {
53-
assert.deepEqual(
54-
invertObject({
55-
$: 'dollar',
56-
_: 'underscore',
57-
num: 1,
58-
u: undefined,
59-
n: null
60-
}),
61-
{
62-
dollar: '$',
63-
underscore: '_'
64-
}
65-
);
66-
});
53+
it('swaps key with value', () => {
54+
assert.deepEqual(invertObject({ foo: 'bar', baz: 'qux' }), {
55+
bar: 'foo',
56+
qux: 'baz'
57+
});
58+
});
6759

68-
describe('options', () => {
69-
it('applies override if provided', () => {
60+
it('swaps key with value if value is string', () => {
7061
assert.deepEqual(
71-
invertObject({ foo: 'bar', baz: 'qux' }, key => {
72-
if (key === 'foo') {
73-
return ['key', 'value'];
74-
}
62+
invertObject({
63+
$: 'dollar',
64+
_: 'underscore',
65+
num: 1,
66+
u: undefined,
67+
n: null
7568
}),
76-
{ key: 'value', qux: 'baz' }
69+
{
70+
dollar: '$',
71+
underscore: '_'
72+
}
7773
);
7874
});
7975

80-
it('does not apply override if invalid', () => {
81-
assert.deepEqual(
82-
invertObject({ foo: 'bar', baz: 'qux' }, key => {
83-
if (key === 'foo') {
84-
return ['key'];
85-
} else if (key === 'baz') {
86-
return { key: 'value' };
87-
}
88-
}),
89-
{ bar: 'foo', qux: 'baz' }
90-
);
76+
describe('options', () => {
77+
it('applies override if provided', () => {
78+
assert.deepEqual(
79+
invertObject({ foo: 'bar', baz: 'qux' }, key => {
80+
if (key === 'foo') {
81+
return ['key', 'value'];
82+
}
83+
}),
84+
{ key: 'value', qux: 'baz' }
85+
);
86+
});
87+
88+
it('does not apply override if invalid', () => {
89+
assert.deepEqual(
90+
invertObject({ foo: 'bar', baz: 'qux' }, key => {
91+
if (key === 'foo') {
92+
return ['key'];
93+
} else if (key === 'baz') {
94+
return { key: 'value' };
95+
}
96+
}),
97+
{ bar: 'foo', qux: 'baz' }
98+
);
99+
});
91100
});
92101
});
93-
});
94102

95-
describe('utilities.isCustomComponent', () => {
96-
it('returns true if the tag contains a hyphen and is not in the whitelist', () => {
97-
assert.equal(isCustomComponent('my-custom-element'), true);
98-
});
103+
describe('isCustomComponent', () => {
104+
it('returns true if the tag contains a hyphen and is not in the whitelist', () => {
105+
assert.strictEqual(isCustomComponent('my-custom-element'), true);
106+
});
99107

100-
it('returns false if the tag is in the whitelist', () => {
101-
assert.equal(isCustomComponent('annotation-xml'), false);
102-
assert.equal(isCustomComponent('color-profile'), false);
103-
assert.equal(isCustomComponent('font-face'), false);
104-
});
108+
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);
112+
});
105113

106-
it('returns true if the props contains an `is` key', () => {
107-
assert.equal(isCustomComponent('button', { is: 'custom-button' }), true);
114+
it('returns true if the props contains an `is` key', () => {
115+
assert.strictEqual(
116+
isCustomComponent('button', { is: 'custom-button' }),
117+
true
118+
);
119+
});
108120
});
109-
});
110121

111-
describe('utilities.PRESERVE_CUSTOM_ATTRIBUTES', () => {
112-
const isReact16AndUp = Number(React.version.match(/^\d./)[0]) >= 16;
122+
describe('PRESERVE_CUSTOM_ATTRIBUTES', () => {
123+
const isReactGreaterThan15 =
124+
parseInt(React.version.match(/^\d./)[0], 10) >= 16;
113125

114-
it(`is ${isReact16AndUp} when React.version="${React.version}"`, () => {
115-
assert.equal(PRESERVE_CUSTOM_ATTRIBUTES, isReact16AndUp);
126+
it(`is ${isReactGreaterThan15} when React.version="${React.version}"`, () => {
127+
assert.strictEqual(PRESERVE_CUSTOM_ATTRIBUTES, isReactGreaterThan15);
128+
});
116129
});
117130
});

0 commit comments

Comments
 (0)