[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.
This commit is contained in:
Aria Buckles
2015-03-11 15:36:51 -07:00
parent d973e32336
commit 206e69c403
2 changed files with 10 additions and 10 deletions
+2 -2
View File
@@ -249,8 +249,8 @@ function checkPropTypes(componentName, propTypes, props, location) {
}
warning(
!error || error instanceof Error,
'%s: the type of %s `%s` is invalid; the type checker function ' +
'must return `null` or an `Error`, but returned a %s. ' +
'%s: type specification of %s `%s` is invalid; the type checker ' +
'function must return `null` or an `Error`, but returned a %s. ' +
'You may have forgotten to pass an argument to the type checker ' +
'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
'shape all require an argument).',
@@ -367,24 +367,24 @@ describe('ReactElementValidator', function() {
var Component = React.createClass({
propTypes: {
prop: React.PropTypes.shape
myProp: React.PropTypes.shape
},
render: function() {
return React.createElement('span', null, this.props.prop.value);
return React.createElement('span', null, this.props.myProp.value);
}
});
ReactTestUtils.renderIntoDocument(
React.createElement(Component, {prop: {value: 'hi'}})
React.createElement(Component, {myProp: {value: 'hi'}})
);
expect(console.warn.calls.length).toBe(1);
expect(console.warn.calls[0].args[0]).toBe(
'Warning: Component: the type of prop `prop` is invalid; the type ' +
'checker function must return `null` or an `Error`, but returned a ' +
'function. You may have forgotten to pass an argument to the type ' +
'checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, ' +
'and shape all require an argument).'
'Warning: Component: type specification of prop `myProp` is invalid; ' +
'the type checker function must return `null` or an `Error`, but ' +
'returned a function. You may have forgotten to pass an argument to ' +
'the type checker creator (arrayOf, instanceOf, objectOf, oneOf, ' +
'oneOfType, and shape all require an argument).'
);
});