@@ -2,7 +2,7 @@ import htmlToDOM from 'html-dom-parser';
2
2
3
3
import domToReact from '../src/dom-to-react' ;
4
4
import * as utilities from '../src/utilities' ;
5
- import { Element } from '../src' ;
5
+ import { Element , type DOMNode , type HTMLReactParserOptions } from '../src' ;
6
6
7
7
import { render } from './helpers' ;
8
8
import { html , svg } from './data' ;
@@ -144,7 +144,7 @@ describe('domToReact', () => {
144
144
} ) ;
145
145
} ) ;
146
146
147
- describe ( 'domToReact with library option' , ( ) => {
147
+ describe ( 'library option' , ( ) => {
148
148
const React = require ( 'react' ) ;
149
149
const Preact = require ( 'preact' ) ;
150
150
@@ -171,7 +171,7 @@ describe('domToReact with library option', () => {
171
171
} ) ;
172
172
} ) ;
173
173
174
- describe ( 'domToReact replace option' , ( ) => {
174
+ describe ( 'replace option' , ( ) => {
175
175
it ( "does not set key if there's a single node" , ( ) => {
176
176
const reactElement = domToReact ( htmlToDOM ( html . single ) , {
177
177
replace : ( ) => < div /> ,
@@ -208,9 +208,26 @@ describe('domToReact replace option', () => {
208
208
expect ( reactElements [ 0 ] . key ) . toBe ( '0' ) ;
209
209
expect ( reactElements [ 1 ] . key ) . toBe ( 'myKey' ) ;
210
210
} ) ;
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
+ } ) ;
211
228
} ) ;
212
229
213
- describe ( 'domToReact transform option' , ( ) => {
230
+ describe ( 'transform option' , ( ) => {
214
231
it ( 'can wrap all elements' , ( ) => {
215
232
const reactElement = domToReact ( htmlToDOM ( html . list ) , {
216
233
transform : ( reactNode , domNode , index ) => {
0 commit comments