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
  • Loading branch information
alexkirsz authored and sophiebits committed Aug 18, 2016
1 parent db6f36b commit 9f5b009
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 @@ -122,6 +122,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 9f5b009

Please sign in to comment.