Skip to content

Commit 57571aa

Browse files
test(dom-to-react): assert replace with children
Relates to #1126
1 parent bf9e00d commit 57571aa

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

__tests__/dom-to-react.test.tsx

+21-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import htmlToDOM from 'html-dom-parser';
22

33
import domToReact from '../src/dom-to-react';
44
import * as utilities from '../src/utilities';
5-
import { Element } from '../src';
5+
import { Element, type DOMNode, type HTMLReactParserOptions } from '../src';
66

77
import { render } from './helpers';
88
import { html, svg } from './data';
@@ -144,7 +144,7 @@ describe('domToReact', () => {
144144
});
145145
});
146146

147-
describe('domToReact with library option', () => {
147+
describe('library option', () => {
148148
const React = require('react');
149149
const Preact = require('preact');
150150

@@ -171,7 +171,7 @@ describe('domToReact with library option', () => {
171171
});
172172
});
173173

174-
describe('domToReact replace option', () => {
174+
describe('replace option', () => {
175175
it("does not set key if there's a single node", () => {
176176
const reactElement = domToReact(htmlToDOM(html.single), {
177177
replace: () => <div />,
@@ -208,9 +208,26 @@ describe('domToReact replace option', () => {
208208
expect(reactElements[0].key).toBe('0');
209209
expect(reactElements[1].key).toBe('myKey');
210210
});
211+
212+
it('replaces with children', () => {
213+
const options: HTMLReactParserOptions = {
214+
replace(domNode) {
215+
if (domNode instanceof Element) {
216+
return <>{domToReact(domNode.children as DOMNode[], options)}</>;
217+
}
218+
},
219+
};
220+
221+
const reactElement = domToReact(
222+
htmlToDOM(html.single),
223+
options,
224+
) as JSX.Element;
225+
226+
expect(reactElement).toBeInstanceOf(Object);
227+
});
211228
});
212229

213-
describe('domToReact transform option', () => {
230+
describe('transform option', () => {
214231
it('can wrap all elements', () => {
215232
const reactElement = domToReact(htmlToDOM(html.list), {
216233
transform: (reactNode, domNode, index) => {

0 commit comments

Comments
 (0)