diff --git a/__tests__/dom-to-react.test.tsx b/__tests__/dom-to-react.test.tsx
index e99509df..92cafb54 100644
--- a/__tests__/dom-to-react.test.tsx
+++ b/__tests__/dom-to-react.test.tsx
@@ -172,6 +172,16 @@ describe('library option', () => {
});
describe('replace option', () => {
+ it.each([undefined, null, 0, 1, true, false, {}])(
+ 'does not replace for invalid return value %p',
+ (value) => {
+ const reactElement = domToReact(htmlToDOM('
'), {
+ replace: () => value,
+ }) as JSX.Element;
+ expect(reactElement).toEqual(
);
+ },
+ );
+
it("does not set key if there's a single node", () => {
const reactElement = domToReact(htmlToDOM(html.single), {
replace: () =>
,
@@ -213,17 +223,12 @@ describe('replace option', () => {
const options: HTMLReactParserOptions = {
replace(domNode) {
if (domNode instanceof Element) {
- return <>{domToReact(domNode.children as DOMNode[], options)}>;
+ return domToReact(domNode.children as DOMNode[], options);
}
},
};
-
- const reactElement = domToReact(
- htmlToDOM(html.single),
- options,
- ) as JSX.Element;
-
- expect(reactElement).toBeInstanceOf(Object);
+ const reactElement = domToReact(htmlToDOM('test
'), options);
+ expect(reactElement).toEqual(test
);
});
});
diff --git a/src/types.ts b/src/types.ts
index c7f0d9f3..d032410f 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -17,7 +17,9 @@ export interface HTMLReactParserOptions {
[key: string]: any;
};
- replace?: (domNode: DOMNode) => JSX.Element | string | null | boolean | void;
+ replace?: (
+ domNode: DOMNode,
+ ) => JSX.Element | string | null | boolean | object | void;
transform?: (
reactNode: ReactNode,