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

Add support for implicitly mocked components using ReactServerRenderer (#9906)

* adds the fix (from stack) and adds a test * updated name of test and ran fiber script

Dominic Gannaway committed Jun 9, 2017 at 17:27 UTC d13f07925fcff7cb07b1491a4021fec84a148041
3 files changed +17
scripts/fiber/tests-passing.txt
+1
@@ -481,6 +481,7 @@ src/renderers/__tests__/ReactIdentity-test.js
481
482 src/renderers/__tests__/ReactMockedComponent-test.js
483 * should allow an implicitly mocked component to be rendered without warnings
484 +* should allow an implicitly mocked component to be rendered without warnings (SSR)
485 * should allow an implicitly mocked component to be updated
486 * has custom methods on the implicitly mocked component
487 * should allow an explicitly mocked component to be rendered
src/renderers/__tests__/ReactMockedComponent-test.js
+8
@@ -16,11 +16,13 @@ var ReactTestUtils;
16
17 var AutoMockedComponent;
18 var MockedComponent;
19 +var ReactDOMServer;
20
21 describe('ReactMockedComponent', () => {
22 beforeEach(() => {
23 React = require('react');
24 ReactTestUtils = require('ReactTestUtils');
25 + ReactDOMServer = require('ReactDOMServer');
26
27 AutoMockedComponent = jest.genMockFromModule(
28 'ReactMockedComponentTestComponent',
@@ -38,6 +40,12 @@ describe('ReactMockedComponent', () => {
40 expectDev(console.error.calls.count()).toBe(0);
41 });
42
43 + it('should allow an implicitly mocked component to be rendered without warnings (SSR)', () => {
44 + spyOn(console, 'error');
45 + ReactDOMServer.renderToString(<AutoMockedComponent />);
46 + expectDev(console.error.calls.count()).toBe(0);
47 + });
48 +
49 it('should allow an implicitly mocked component to be updated', () => {
50 class Wrapper extends React.Component {
51 state = {foo: 1};
src/renderers/shared/server/ReactServerRenderer.js
+8
@@ -321,6 +321,14 @@ function resolve(child, context) {
321 }
322 child = inst.render();
323
324 + if (__DEV__) {
325 + if (child === undefined && inst.render._isMockFunction) {
326 + // This is probably bad practice. Consider warning here and
327 + // deprecating this convenience.
328 + child = null;
329 + }
330 + }
331 +
332 var childContext = inst.getChildContext && inst.getChildContext();
333 if (childContext) {
334 context = Object.assign({}, context, childContext);