Skip to content

Commit

Permalink
Fix ReactTestInstance::toJSON() with empty top-level components (#7523)
Browse files Browse the repository at this point in the history
(cherry picked from commit 9f5b009)
  • Loading branch information
alexkirsz authored and zpao committed Aug 19, 2016
1 parent 421bb8c commit f120c1b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/renderers/testing/ReactTestMount.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down
8 changes: 8 additions & 0 deletions src/renderers/testing/__tests__/ReactTestRenderer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ describe('ReactTestRenderer', function() {
});
});

it('renders a top-level empty component', function() {
function Empty() {
return null;
}
var renderer = ReactTestRenderer.create(<Empty />);
expect(renderer.toJSON()).toEqual(null);
});

it('exposes a type flag', function() {
function Link() {
return <a role="link" />;
Expand Down

0 comments on commit f120c1b

Please sign in to comment.