diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index d8372e5042..13e64c130e 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -481,6 +481,7 @@ src/renderers/__tests__/ReactIdentity-test.js src/renderers/__tests__/ReactMockedComponent-test.js * should allow an implicitly mocked component to be rendered without warnings +* should allow an implicitly mocked component to be rendered without warnings (SSR) * should allow an implicitly mocked component to be updated * has custom methods on the implicitly mocked component * should allow an explicitly mocked component to be rendered diff --git a/src/renderers/__tests__/ReactMockedComponent-test.js b/src/renderers/__tests__/ReactMockedComponent-test.js index 38083e4f9c..061094b511 100644 --- a/src/renderers/__tests__/ReactMockedComponent-test.js +++ b/src/renderers/__tests__/ReactMockedComponent-test.js @@ -16,11 +16,13 @@ var ReactTestUtils; var AutoMockedComponent; var MockedComponent; +var ReactDOMServer; describe('ReactMockedComponent', () => { beforeEach(() => { React = require('react'); ReactTestUtils = require('ReactTestUtils'); + ReactDOMServer = require('ReactDOMServer'); AutoMockedComponent = jest.genMockFromModule( 'ReactMockedComponentTestComponent', @@ -38,6 +40,12 @@ describe('ReactMockedComponent', () => { expectDev(console.error.calls.count()).toBe(0); }); + it('should allow an implicitly mocked component to be rendered without warnings (SSR)', () => { + spyOn(console, 'error'); + ReactDOMServer.renderToString(); + expectDev(console.error.calls.count()).toBe(0); + }); + it('should allow an implicitly mocked component to be updated', () => { class Wrapper extends React.Component { state = {foo: 1}; diff --git a/src/renderers/shared/server/ReactServerRenderer.js b/src/renderers/shared/server/ReactServerRenderer.js index fc86b3bf2c..6b0e758b75 100644 --- a/src/renderers/shared/server/ReactServerRenderer.js +++ b/src/renderers/shared/server/ReactServerRenderer.js @@ -321,6 +321,14 @@ function resolve(child, context) { } child = inst.render(); + if (__DEV__) { + if (child === undefined && inst.render._isMockFunction) { + // This is probably bad practice. Consider warning here and + // deprecating this convenience. + child = null; + } + } + var childContext = inst.getChildContext && inst.getChildContext(); if (childContext) { context = Object.assign({}, context, childContext);