Fix ReactTestInstance::toJSON() with empty top-level components (#7523)

(cherry picked from commit 9f5b009f05)
This commit is contained in:
Alexandre Kirszenberg
2016-08-18 22:02:09 +02:00
committed by Paul O’Shannessy
parent 421bb8c53a
commit f120c1b78e
2 changed files with 11 additions and 0 deletions
+3
View File
@@ -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();
};
@@ -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" />;