Add test for mocked render functions
Treat them as if they return null
Andrew Clark committed
Jan 17, 2017 at 11:48 UTC
645ad6d261c0c02ab9b383ea1b73185550cfd4ae
3 files changed
+10
-2
scripts/fiber/tests-passing.txt
+1
@@ -554,6 +554,7 @@ src/renderers/dom/fiber/__tests__/ReactDOMFiber-test.js
554
* should not crash encountering low-priority tree
555
* throws if non-element passed to top-level render
556
* throws if something other than false, null, or an element is returned from render
557
+* treats mocked render functions as if they return null
558
559
src/renderers/dom/shared/__tests__/CSSProperty-test.js
560
* should generate browser prefixes for its `isUnitlessNumber`
src/renderers/dom/fiber/__tests__/ReactDOMFiber-test.js
+7
@@ -1131,4 +1131,11 @@ describe('disableNewFiberFeatures', () => {
1131
expect(() => ReactDOM.render(<Render>{999}</Render>, container)).toThrow(/You may have returned undefined/);
1132
expect(() => ReactDOM.render(<Render>[<div />]</Render>, container)).toThrow(/You may have returned undefined/);
1133
});
1134
+
1135
+ it('treats mocked render functions as if they return null', () => {
1136
+ class Mocked extends React.Component {}
1137
+ Mocked.prototype.render = jest.fn();
1138
+ ReactDOM.render(<Mocked />, container);
1139
+ expect(container.textContent).toEqual('');
1140
+ });
1141
});
src/renderers/shared/fiber/ReactChildFiber.js
+2
-2
@@ -1130,7 +1130,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
1130
case ClassComponent: {
1131
if (__DEV__) {
1132
const instance = returnFiber.stateNode;
1133
- if (instance.render._isMockFunction) {
1133
+ if (instance.render._isMockFunction && typeof newChild === 'undefined') {
1134
// We allow auto-mocks to proceed as if they're
1135
// returning null.
1136
break;
@@ -1254,7 +1254,7 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
1254
case ClassComponent: {
1255
if (__DEV__) {
1256
const instance = returnFiber.stateNode;
1257
- if (instance.render._isMockFunction) {
1257
+ if (instance.render._isMockFunction && typeof newChild === 'undefined') {
1258
// We allow auto-mocks to proceed as if they're returning null.
1259
break;
1260
}