Fix ReactTestInstance::toJSON() with empty top-level components (#7523)
Alexandre Kirszenberg committed
Aug 18, 2016 at 22:02 UTC
9f5b009f056d90e8d6a2a78c0e1292b00d33e019
2 files changed
+11
src/renderers/testing/ReactTestMount.js
+3
@@ -122,6 +122,9 @@ ReactTestInstance.prototype.unmount = function(nextElement) {
122
};
123
ReactTestInstance.prototype.toJSON = function() {
124
var inst = getHostComponentFromComposite(this._component);
125
+ if (inst === null) {
126
+ return null;
127
+ }
128
return inst.toJSON();
129
};
130
src/renderers/testing/__tests__/ReactTestRenderer-test.js
+8
@@ -28,6 +28,14 @@ describe('ReactTestRenderer', function() {
28
});
29
});
30
31
+ it('renders a top-level empty component', function() {
32
+ function Empty() {
33
+ return null;
34
+ }
35
+ var renderer = ReactTestRenderer.create(<Empty />);
36
+ expect(renderer.toJSON()).toEqual(null);
37
+ });
38
+
39
it('exposes a type flag', function() {
40
function Link() {
41
return <a role="link" />;