diff --git a/src/isomorphic/classic/types/ReactPropTypes.js b/src/isomorphic/classic/types/ReactPropTypes.js index ec060fbde7..eab133b350 100644 --- a/src/isomorphic/classic/types/ReactPropTypes.js +++ b/src/isomorphic/classic/types/ReactPropTypes.js @@ -236,11 +236,13 @@ function createArrayOfTypeChecker(typeChecker) { function createElementTypeChecker() { function validate(props, propName, componentName, location, propFullName) { - if (!ReactElement.isValidElement(props[propName])) { + var propValue = props[propName]; + if (!ReactElement.isValidElement(propValue)) { var locationName = ReactPropTypeLocationNames[location]; + var propType = getPropType(propValue); return new Error( - `Invalid ${locationName} \`${propFullName}\` supplied to ` + - `\`${componentName}\`, expected a single ReactElement.` + `Invalid ${locationName} \`${propFullName}\` of type ` + + `\`${propType}\` supplied to \`${componentName}\`, expected a single ReactElement.` ); } return null; diff --git a/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js b/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js index b11179a11f..bee48f5407 100644 --- a/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js +++ b/src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js @@ -356,12 +356,30 @@ describe('ReactPropTypes', function() { }); it('should not support multiple components or scalar values', () => { - var message = 'Invalid prop `testProp` supplied to `testComponent`, ' + - 'expected a single ReactElement.'; - typeCheckFail(PropTypes.element, [
, ], message); - typeCheckFail(PropTypes.element, 123, message); - typeCheckFail(PropTypes.element, 'foo', message); - typeCheckFail(PropTypes.element, false, message); + typeCheckFail( + PropTypes.element, + [, ], + 'Invalid prop `testProp` of type `array` supplied to `testComponent`, ' + + 'expected a single ReactElement.' + ); + typeCheckFail( + PropTypes.element, + 123, + 'Invalid prop `testProp` of type `number` supplied to `testComponent`, ' + + 'expected a single ReactElement.' + ); + typeCheckFail( + PropTypes.element, + 'foo', + 'Invalid prop `testProp` of type `string` supplied to `testComponent`, ' + + 'expected a single ReactElement.' + ); + typeCheckFail( + PropTypes.element, + false, + 'Invalid prop `testProp` of type `boolean` supplied to `testComponent`, ' + + 'expected a single ReactElement.' + ); }); it('should be able to define a single child as label', () => {