Merge pull request #2867 from zpao/no-warn-mock-methods

Don't warn about plain classes when in mocked components
This commit is contained in:
Paul O’Shannessy
2015-01-15 16:45:05 -08:00
4 changed files with 12 additions and 7 deletions
+3 -3
View File
@@ -818,13 +818,13 @@ var ReactClass = {
// mistake so we'll warn you to use the static property, property
// initializer or constructor respectively.
if (Constructor.getDefaultProps) {
Constructor.getDefaultProps._isReactClassApproved = true;
Constructor.getDefaultProps.isReactClassApproved = {};
}
if (Constructor.prototype.getInitialState) {
Constructor.prototype.getInitialState._isReactClassApproved = true;
Constructor.prototype.getInitialState.isReactClassApproved = {};
}
if (Constructor.prototype.componentWillMount) {
Constructor.prototype.componentWillMount._isReactClassApproved = true;
Constructor.prototype.componentWillMount.isReactClassApproved = {};
}
}
+1 -1
View File
@@ -380,7 +380,7 @@ var ReactElementValidator = {
}
if (typeof type.getDefaultProps === 'function') {
warning(
type.getDefaultProps._isReactClassApproved,
type.getDefaultProps.isReactClassApproved,
'getDefaultProps is only used on classic React.createClass ' +
'definitions. Use a static property named `defaultProps` instead.'
);
+2 -2
View File
@@ -204,7 +204,7 @@ var ReactCompositeComponentMixin = assign({},
// catch them here, at initialization time, instead.
warning(
!inst.getInitialState ||
inst.getInitialState._isReactClassApproved,
inst.getInitialState.isReactClassApproved,
'getInitialState was defined on %s, a plain JavaScript class. ' +
'This is only supported for classes created using React.createClass. ' +
'Did you mean to define a state property instead?',
@@ -212,7 +212,7 @@ var ReactCompositeComponentMixin = assign({},
);
warning(
!inst.componentWillMount ||
inst.componentWillMount._isReactClassApproved,
inst.componentWillMount.isReactClassApproved,
'componentWillMount was defined on %s, a plain JavaScript class. ' +
'This is only supported for classes created using React.createClass. ' +
'Did you mean to define a constructor instead?',
@@ -31,6 +31,9 @@ describe('ReactMockedComponent', function() {
ReactTestUtils = require('ReactTestUtils');
OriginalComponent = React.createClass({
getDefaultProps: function() {
return { bar: 'baz' };
},
getInitialState: function() {
return { foo: 'bar' };
@@ -54,8 +57,10 @@ describe('ReactMockedComponent', function() {
ReactTestUtils.mockComponent(MockedComponent);
});
it('should allow an implicitly mocked component to be rendered', () => {
it('should allow an implicitly mocked component to be rendered without warnings', () => {
spyOn(console, 'warn');
ReactTestUtils.renderIntoDocument(<AutoMockedComponent />);
expect(console.warn.calls.length).toBe(0);
});
it('should allow an implicitly mocked component to be updated', () => {