From f120c1b78e92b375d889608e4eb8a5cbe80e10ff Mon Sep 17 00:00:00 2001 From: Alexandre Kirszenberg Date: Thu, 18 Aug 2016 22:02:09 +0200 Subject: [PATCH] Fix ReactTestInstance::toJSON() with empty top-level components (#7523) (cherry picked from commit 9f5b009f056d90e8d6a2a78c0e1292b00d33e019) --- src/renderers/testing/ReactTestMount.js | 3 +++ src/renderers/testing/__tests__/ReactTestRenderer-test.js | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/src/renderers/testing/ReactTestMount.js b/src/renderers/testing/ReactTestMount.js index f297691b1889e..c022b9f356936 100644 --- a/src/renderers/testing/ReactTestMount.js +++ b/src/renderers/testing/ReactTestMount.js @@ -127,6 +127,9 @@ ReactTestInstance.prototype.unmount = function(nextElement) { }; ReactTestInstance.prototype.toJSON = function() { var inst = getHostComponentFromComposite(this._component); + if (inst === null) { + return null; + } return inst.toJSON(); }; diff --git a/src/renderers/testing/__tests__/ReactTestRenderer-test.js b/src/renderers/testing/__tests__/ReactTestRenderer-test.js index a20d442686d3b..24fff957ddc46 100644 --- a/src/renderers/testing/__tests__/ReactTestRenderer-test.js +++ b/src/renderers/testing/__tests__/ReactTestRenderer-test.js @@ -28,6 +28,14 @@ describe('ReactTestRenderer', function() { }); }); + it('renders a top-level empty component', function() { + function Empty() { + return null; + } + var renderer = ReactTestRenderer.create(); + expect(renderer.toJSON()).toEqual(null); + }); + it('exposes a type flag', function() { function Link() { return ;