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
This commit is contained in:
Dominic Gannaway
2017-06-09 16:27:00 +01:00
committed by Dan Abramov
parent 47731c9f74
commit d13f07925f
3 changed files with 17 additions and 0 deletions
+1
View File
@@ -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
@@ -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(<AutoMockedComponent />);
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};
@@ -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);