@samitouri / QOS-React-2 / commits / 80cf21cae4

In DEV, allow treat auto-mocked render methods as if they return null

Consider deprecating this in the future.

Andrew Clark committed Jan 11, 2017 at 18:06 UTC 80cf21cae49d370cd8df07c9c354c251c924376a
1 file changed +24 -2
src/renderers/shared/fiber/ReactChildFiber.js
+24 -2
@@ -1127,8 +1127,19 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
1127 }
1128
1129 const Component = returnFiber.type;
1130 + let validEmptyReturnType = newChild === null || newChild === false;
1131 +
1132 + if (__DEV__) {
1133 + if (!validEmptyReturnType &&
1134 + returnFiber.tag === ClassComponent &&
1135 + returnFiber.stateNode.render._isMockFunction) {
1136 + // We allow auto-mocks to proceed as if they're returning null.
1137 + validEmptyReturnType = true;
1138 + }
1139 + }
1140 +
1141 invariant(
1131 - newChild === null || newChild === false,
1142 + validEmptyReturnType,
1143 '%s.render(): A valid React element (or null) must be returned. You ' +
1144 'may have returned undefined, an array or some other invalid object.',
1145 Component.displayName || Component.name || 'Component'
@@ -1204,7 +1215,18 @@ function ChildReconciler(shouldClone, shouldTrackSideEffects) {
1215 case HostRoot:
1216 // TODO: Top-level render
1217 break;
1207 - case ClassComponent:
1218 + case ClassComponent: {
1219 + if (__DEV__) {
1220 + const instance = returnFiber.stateNode;
1221 + if (instance.render._isMockFunction) {
1222 + // We allow auto-mocks to proceed as if they're returning null.
1223 + break;
1224 + }
1225 + }
1226 + }
1227 + // Intentionally fall through to the next case, which handles both
1228 + // functions and classes
1229 + // eslint-disable-next-lined no-fallthrough
1230 case FunctionalComponent: {
1231 const Component = returnFiber.type;
1232 invariant(