@samitouri / QOS-React-2 / commits / e952869ff8

Support rendering to null in ShallowComponentRenderer

Reviewers: @sema, @zpao Test Plan: ``` $ npm jest ```

yungsters committed Feb 18, 2015 at 11:30 UTC e952869ff896bc9b1bff8d4238a2256758015c11
2 files changed +25 -3
src/test/ReactTestUtils.js
+10 -3
@@ -16,6 +16,7 @@ var EventPluginHub = require('EventPluginHub');
16 var EventPropagators = require('EventPropagators');
17 var React = require('React');
18 var ReactElement = require('ReactElement');
19 +var ReactEmptyComponent = require('ReactEmptyComponent');
20 var ReactBrowserEventEmitter = require('ReactBrowserEventEmitter');
21 var ReactCompositeComponent = require('ReactCompositeComponent');
22 var ReactInstanceHandles = require('ReactInstanceHandles');
@@ -323,13 +324,16 @@ var ReactShallowRenderer = function() {
324 ReactShallowRenderer.prototype.getRenderOutput = function() {
325 return (
326 (this._instance && this._instance._renderedComponent &&
326 - this._instance._renderedComponent._currentElement)
327 + this._instance._renderedComponent._renderedOutput)
328 || null
329 );
330 };
331
332 var NoopInternalComponent = function(element) {
332 - this._currentElement = element;
333 + this._renderedOutput = element;
334 + this._currentElement = element === null || element === false ?
335 + ReactEmptyComponent.emptyElement :
336 + element;
337 }
338
339 NoopInternalComponent.prototype = {
@@ -338,7 +342,10 @@ NoopInternalComponent.prototype = {
342 },
343
344 receiveComponent: function(element) {
341 - this._currentElement = element;
345 + this._renderedOutput = element;
346 + this._currentElement = element === null || element === false ?
347 + ReactEmptyComponent.emptyElement :
348 + element;
349 },
350
351 unmountComponent: function() {
src/test/__tests__/ReactTestUtils-test.js
+15
@@ -57,6 +57,21 @@ describe('ReactTestUtils', function() {
57 ]);
58 });
59
60 + it('can shallow render to null', function() {
61 + var SomeComponent = React.createClass({
62 + render: function() {
63 + return null;
64 + }
65 + });
66 +
67 + var shallowRenderer = ReactTestUtils.createRenderer();
68 + shallowRenderer.render(<SomeComponent />, {});
69 +
70 + var result = shallowRenderer.getRenderOutput();
71 +
72 + expect(result).toBe(null);
73 + });
74 +
75 it('lets you update shallowly rendered components', function() {
76 var SomeComponent = React.createClass({
77 getInitialState: function() {