Skip to content

Commit 320c364

Browse files
test(html-to-react): add test that verifies domToReact is exported
1 parent 1fb5ee2 commit 320c364

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

test/html-to-react.js

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
const assert = require('assert');
22
const React = require('react');
3-
const Parser = require('../');
3+
const parse = require('../');
44
const { data, render } = require('./helpers/');
55

66
describe('html-to-react', () => {
77
describe('parser', () => {
88
[undefined, null, {}, [], 42].forEach(value => {
99
it(`throws an error if first argument is ${value}`, () => {
1010
assert.throws(() => {
11-
Parser(value);
11+
parse(value);
1212
}, TypeError);
1313
});
1414
});
1515

1616
it('returns string if it cannot be parsed as HTML', () => {
17-
assert.equal(Parser('foo'), 'foo');
17+
assert.equal(parse('foo'), 'foo');
1818
});
1919

2020
it('converts single HTML element to React', () => {
2121
const html = data.html.single;
22-
const reactElement = Parser(html);
22+
const reactElement = parse(html);
2323
assert.equal(render(reactElement), html);
2424
});
2525

2626
it('converts single HTML element and ignores comment', () => {
2727
const html = data.html.single;
2828
// comment should be ignored
29-
const reactElement = Parser(html + data.html.comment);
29+
const reactElement = parse(html + data.html.comment);
3030
assert.equal(render(reactElement), html);
3131
});
3232

3333
it('converts multiple HTML elements to React', () => {
3434
const html = data.html.multiple;
35-
const reactElements = Parser(html);
35+
const reactElements = parse(html);
3636
assert.equal(
3737
render(React.createElement('div', {}, reactElements)),
3838
'<div>' + html + '</div>'
@@ -41,26 +41,26 @@ describe('html-to-react', () => {
4141

4242
it('converts complex HTML to React', () => {
4343
const html = data.html.complex;
44-
const reactElement = Parser(data.html.doctype + html);
44+
const reactElement = parse(data.html.doctype + html);
4545
assert.equal(render(reactElement), html);
4646
});
4747

4848
it('converts empty <style> to React', () => {
4949
const html = '<style></style>';
50-
const reactElement = Parser(html);
50+
const reactElement = parse(html);
5151
assert.equal(render(reactElement), html);
5252
});
5353

5454
it('converts SVG to React', () => {
5555
const svg = data.svg.complex;
56-
const reactElement = Parser(svg);
56+
const reactElement = parse(svg);
5757
assert.equal(render(reactElement), svg);
5858
});
5959

6060
it('decodes HTML entities', () => {
6161
const encodedEntities = 'asdf &amp; &yuml; &uuml; &apos;';
6262
const decodedEntities = "asdf & ÿ ü '";
63-
const reactElement = Parser('<i>' + encodedEntities + '</i>');
63+
const reactElement = parse('<i>' + encodedEntities + '</i>');
6464
assert.equal(reactElement.props.children, decodedEntities);
6565
});
6666
});
@@ -69,7 +69,7 @@ describe('html-to-react', () => {
6969
describe('replace', () => {
7070
it('overrides the element if replace is valid', () => {
7171
const html = data.html.complex;
72-
const reactElement = Parser(html, {
72+
const reactElement = parse(html, {
7373
replace: node => {
7474
if (node.name === 'title') {
7575
return React.createElement('title', {}, 'Replaced Title');
@@ -84,7 +84,7 @@ describe('html-to-react', () => {
8484

8585
it('does not override the element if replace is invalid', () => {
8686
const html = data.html.complex;
87-
const reactElement = Parser(html, {
87+
const reactElement = parse(html, {
8888
replace: node => {
8989
if (node.attribs && node.attribs.id === 'header') {
9090
return {
@@ -105,3 +105,9 @@ describe('html-to-react', () => {
105105
});
106106
});
107107
});
108+
109+
describe('dom-to-react', () => {
110+
it('exports domToReact', () => {
111+
assert.equal(parse.domToReact, require('../lib/dom-to-react'));
112+
});
113+
});

0 commit comments

Comments
 (0)