[PropTypes] Make invalid proptype warning clearer
Addresses comments on #3383, making the invalid proptype specification warning clearer and making the tests for it a bit clearer.
Aria Buckles committed
Mar 11, 2015 at 15:34 UTC
206e69c4034eef1e0c51467ffe7f44002f638111
2 files changed
+10
-10
src/classic/element/ReactElementValidator.js
+2
-2
@@ -249,8 +249,8 @@ function checkPropTypes(componentName, propTypes, props, location) {
249
}
250
warning(
251
!error || error instanceof Error,
252
- '%s: the type of %s `%s` is invalid; the type checker function ' +
253
- 'must return `null` or an `Error`, but returned a %s. ' +
252
+ '%s: type specification of %s `%s` is invalid; the type checker ' +
253
+ 'function must return `null` or an `Error`, but returned a %s. ' +
254
'You may have forgotten to pass an argument to the type checker ' +
255
'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
256
'shape all require an argument).',
src/classic/element/__tests__/ReactElementValidator-test.js
+8
-8
@@ -367,24 +367,24 @@ describe('ReactElementValidator', function() {
367
368
var Component = React.createClass({
369
propTypes: {
370
- prop: React.PropTypes.shape
370
+ myProp: React.PropTypes.shape
371
},
372
render: function() {
373
- return React.createElement('span', null, this.props.prop.value);
373
+ return React.createElement('span', null, this.props.myProp.value);
374
}
375
});
376
377
ReactTestUtils.renderIntoDocument(
378
- React.createElement(Component, {prop: {value: 'hi'}})
378
+ React.createElement(Component, {myProp: {value: 'hi'}})
379
);
380
381
expect(console.warn.calls.length).toBe(1);
382
expect(console.warn.calls[0].args[0]).toBe(
383
- 'Warning: Component: the type of prop `prop` is invalid; the type ' +
384
- 'checker function must return `null` or an `Error`, but returned a ' +
385
- 'function. You may have forgotten to pass an argument to the type ' +
386
- 'checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, ' +
387
- 'and shape all require an argument).'
383
+ 'Warning: Component: type specification of prop `myProp` is invalid; ' +
384
+ 'the type checker function must return `null` or an `Error`, but ' +
385
+ 'returned a function. You may have forgotten to pass an argument to ' +
386
+ 'the type checker creator (arrayOf, instanceOf, objectOf, oneOf, ' +
387
+ 'oneOfType, and shape all require an argument).'
388
);
389
});
390