Don't warn about plain classes when in mocked components
Mocking both doesn't copy properties that start with an underscore, nor does it copy values, only nested objects.
Paul O’Shannessy committed
Jan 15, 2015 at 15:05 UTC
069aec1d4250cbda5be61c949a16f1005f8b0b97
4 files changed
+12
-7
src/classic/class/ReactClass.js
+3
-3
@@ -818,13 +818,13 @@ var ReactClass = {
818
// mistake so we'll warn you to use the static property, property
819
// initializer or constructor respectively.
820
if (Constructor.getDefaultProps) {
821
- Constructor.getDefaultProps._isReactClassApproved = true;
821
+ Constructor.getDefaultProps.isReactClassApproved = {};
822
}
823
if (Constructor.prototype.getInitialState) {
824
- Constructor.prototype.getInitialState._isReactClassApproved = true;
824
+ Constructor.prototype.getInitialState.isReactClassApproved = {};
825
}
826
if (Constructor.prototype.componentWillMount) {
827
- Constructor.prototype.componentWillMount._isReactClassApproved = true;
827
+ Constructor.prototype.componentWillMount.isReactClassApproved = {};
828
}
829
}
830
src/classic/element/ReactElementValidator.js
+1
-1
@@ -380,7 +380,7 @@ var ReactElementValidator = {
380
}
381
if (typeof type.getDefaultProps === 'function') {
382
warning(
383
- type.getDefaultProps._isReactClassApproved,
383
+ type.getDefaultProps.isReactClassApproved,
384
'getDefaultProps is only used on classic React.createClass ' +
385
'definitions. Use a static property named `defaultProps` instead.'
386
);
src/core/ReactCompositeComponent.js
+2
-2
@@ -204,7 +204,7 @@ var ReactCompositeComponentMixin = assign({},
204
// catch them here, at initialization time, instead.
205
warning(
206
!inst.getInitialState ||
207
- inst.getInitialState._isReactClassApproved,
207
+ inst.getInitialState.isReactClassApproved,
208
'getInitialState was defined on %s, a plain JavaScript class. ' +
209
'This is only supported for classes created using React.createClass. ' +
210
'Did you mean to define a state property instead?',
@@ -212,7 +212,7 @@ var ReactCompositeComponentMixin = assign({},
212
);
213
warning(
214
!inst.componentWillMount ||
215
- inst.componentWillMount._isReactClassApproved,
215
+ inst.componentWillMount.isReactClassApproved,
216
'componentWillMount was defined on %s, a plain JavaScript class. ' +
217
'This is only supported for classes created using React.createClass. ' +
218
'Did you mean to define a constructor instead?',
src/core/__tests__/ReactMockedComponent-test.js
+6
-1
@@ -31,6 +31,9 @@ describe('ReactMockedComponent', function() {
31
ReactTestUtils = require('ReactTestUtils');
32
33
OriginalComponent = React.createClass({
34
+ getDefaultProps: function() {
35
+ return { bar: 'baz' };
36
+ },
37
38
getInitialState: function() {
39
return { foo: 'bar' };
@@ -54,8 +57,10 @@ describe('ReactMockedComponent', function() {
57
ReactTestUtils.mockComponent(MockedComponent);
58
});
59
57
- it('should allow an implicitly mocked component to be rendered', () => {
60
+ it('should allow an implicitly mocked component to be rendered without warnings', () => {
61
+ spyOn(console, 'warn');
62
ReactTestUtils.renderIntoDocument(<AutoMockedComponent />);
63
+ expect(console.warn.calls.length).toBe(0);
64
});
65
66
it('should allow an implicitly mocked component to be updated', () => {