Skip to content

Commit f3e5645

Browse files
test: add tests to verify domhandler classes are exported
1 parent 4fc3a73 commit f3e5645

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

test/index.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const React = require('react');
2+
const domhandler = require('domhandler');
23
const parse = require('..');
34
const { html, svg } = require('./data');
45
const { render } = require('./helpers');
@@ -24,6 +25,16 @@ describe('module', () => {
2425
expect(parse.attributesToProps).toBe(require('../lib/attributes-to-props'));
2526
expect(parse.attributesToProps).toBeInstanceOf(Function);
2627
});
28+
29+
describe('domhandler', () => {
30+
it.each(['Comment', 'Element', 'Node', 'ProcessingInstruction', 'Text'])(
31+
'exports %s',
32+
name => {
33+
expect(parse[name]).toBeInstanceOf(Function);
34+
expect(parse[name]).toBe(domhandler[name]);
35+
}
36+
);
37+
});
2738
});
2839

2940
describe('HTMLReactParser', () => {

test/integration/index.test.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
describe.each([
2-
['unminified', '../../dist/html-react-parser'],
3-
['minified', '../../dist/html-react-parser.min']
2+
['minified', '../../dist/html-react-parser.min'],
3+
['unminified', '../../dist/html-react-parser']
44
])('UMD %s', (_type, path) => {
55
const parse = require(path);
66

7-
it('exports the parser', () => {
7+
it('exports parser', () => {
88
expect(parse).toBeInstanceOf(Function);
99
});
1010

1111
it('exports default', () => {
1212
expect(parse.default).toBeInstanceOf(Function);
1313
});
1414

15-
it('exports domToReact', () => {
16-
expect(parse.domToReact).toBeInstanceOf(Function);
15+
describe('internal', () => {
16+
it.each(['attributesToProps', 'domToReact', 'htmlToDOM'])(
17+
'exports %s',
18+
name => {
19+
expect(parse[name]).toBeInstanceOf(Function);
20+
}
21+
);
1722
});
1823

19-
it('exports htmlToDOM', () => {
20-
expect(parse.htmlToDOM).toBeInstanceOf(Function);
21-
});
22-
23-
it('exports attributesToProps', () => {
24-
expect(parse.attributesToProps).toBeInstanceOf(Function);
24+
describe('domhandler', () => {
25+
it.each(['Comment', 'Element', 'Node', 'ProcessingInstruction', 'Text'])(
26+
'exports %s',
27+
name => {
28+
expect(parse[name]).toBeInstanceOf(Function);
29+
}
30+
);
2531
});
2632
});

test/module/index.mjs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
import assert from 'assert';
22
import parse, {
3+
attributesToProps,
34
domToReact,
4-
htmlToDOM,
5-
attributesToProps
5+
htmlToDOM
6+
} from '../../index.mjs';
7+
import {
8+
Comment,
9+
Element,
10+
Node,
11+
ProcessingInstruction,
12+
Text
613
} from '../../index.mjs';
714

815
[parse, domToReact, htmlToDOM, attributesToProps].forEach(func => {
916
assert.strictEqual(typeof func, 'function');
1017
});
18+
19+
// domhandler
20+
[Comment, Element, Node, ProcessingInstruction, Text].forEach(func => {
21+
assert.strictEqual(typeof func, 'function');
22+
});

0 commit comments

Comments
 (0)