Skip to content

Commit 1a32b65

Browse files
test(types): fix and improve dts tests for dom-to-react.test.tsx
1 parent 3938f56 commit 1a32b65

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

test/types/lib/dom-to-react.test.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
1+
import { DomElement } from 'domhandler';
12
import { HTMLReactParserOptions } from 'html-react-parser';
23
import domToReact from 'html-react-parser/lib/dom-to-react';
34
import * as React from 'react';
45
import htmlToDOM from 'html-dom-parser';
56

6-
/* $ExpectType ReactElement | ReactElement[] */
7-
domToReact(htmlToDOM('<div>text</div>'));
7+
// $ExpectType DomElement[]
8+
htmlToDOM('<div>text</div>');
89

9-
// `options.replace`
10+
// $ExpectType Element | Element[]
11+
domToReact(htmlToDOM('<div>text</div>'));
1012

11-
// Return React.createElement from `replace`
13+
// $ExpectType Element | Element[]
1214
domToReact(htmlToDOM('<p id="replace">text</p>'), {
1315
replace: domNode => {
1416
if (domNode.attribs && domNode.attribs.id === 'replace') {
15-
return React.createElement('span', {}, 'replaced');
17+
return <span>replaced</span>;
1618
}
1719
}
1820
});
1921

20-
// Return ReactElement
21-
const options: HTMLReactParserOptions = {
22+
let options: HTMLReactParserOptions;
23+
24+
options = {
2225
replace({ attribs }) {
23-
return attribs && attribs.id === 'remove' && <React.Fragment />;
26+
return attribs && attribs.id === 'remove' && <></>;
2427
}
2528
};
2629

30+
// $ExpectType Element | Element[]
2731
domToReact(htmlToDOM('<p><br id="remove"></p>'), options);
2832

29-
// Return domhandler node
33+
// $ExpectType Element | Element[]
3034
domToReact(htmlToDOM('<a id="header" href="#">Heading</a>'), {
3135
replace: node => {
3236
if (node.attribs && node.attribs.id === 'header') {
33-
return {
34-
type: 'h1',
35-
props: { children: 'Heading' }
36-
};
37+
return;
3738
}
3839
}
3940
});

0 commit comments

Comments
 (0)