From fb7da289456191ab5c3d2de24fe66b86eedcb98b Mon Sep 17 00:00:00 2001 From: Francisco Presencia Date: Fri, 24 Jan 2020 15:12:59 +0900 Subject: [PATCH] Allow any child node type (#10) --- src/index.js | 2 +- test/react-jsdom.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 358f52d..69bc311 100644 --- a/src/index.js +++ b/src/index.js @@ -26,7 +26,7 @@ const ReactJSDOM = { global[prop] = origGlobals[prop]; }); - return container.children[0]; + return container.childNodes[0]; } }; diff --git a/test/react-jsdom.js b/test/react-jsdom.js index 8b160f4..bfab14c 100644 --- a/test/react-jsdom.js +++ b/test/react-jsdom.js @@ -35,6 +35,26 @@ test('ReactJSDOM renders a React Component', t => { t.is(elem.textContent, 'hi'); }); +test('ReactJSDOM renders a React Fragment', t => { + const elem = ReactJSDOM.render(( + + )); + t.is(elem.nodeName, 'DIV'); + t.is(elem.textContent, 'hi'); +}); + +test('ReactJSDOM renders a Text String', t => { + const elem = ReactJSDOM.render('Hello world'); + t.is(elem.nodeName, '#text'); + t.is(elem.textContent, 'Hello world'); +}); + +test('ReactJSDOM renders a Fragment wrapping a text string', t => { + const elem = ReactJSDOM.render(Hello world); + t.is(elem.nodeName, '#text'); + t.is(elem.textContent, 'Hello world'); +}); + test('ReactJSDOM allows window instance to be passed in', t => { const window = new Window(); const elem = ReactJSDOM.render(, window);