Mention actual prop type in element type checker (#7319)
Alex Zherdev committed
Jul 20, 2016 at 21:16 UTC
8bcea5310e4ac21c7c4f0552c01a270c4746b08b
2 files changed
+29
-9
src/isomorphic/classic/types/ReactPropTypes.js
+5
-3
@@ -236,11 +236,13 @@ function createArrayOfTypeChecker(typeChecker) {
236
237
function createElementTypeChecker() {
238
function validate(props, propName, componentName, location, propFullName) {
239
- if (!ReactElement.isValidElement(props[propName])) {
239
+ var propValue = props[propName];
240
+ if (!ReactElement.isValidElement(propValue)) {
241
var locationName = ReactPropTypeLocationNames[location];
242
+ var propType = getPropType(propValue);
243
return new Error(
242
- `Invalid ${locationName} \`${propFullName}\` supplied to ` +
243
- `\`${componentName}\`, expected a single ReactElement.`
244
+ `Invalid ${locationName} \`${propFullName}\` of type ` +
245
+ `\`${propType}\` supplied to \`${componentName}\`, expected a single ReactElement.`
246
);
247
}
248
return null;
src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
+24
-6
@@ -356,12 +356,30 @@ describe('ReactPropTypes', function() {
356
});
357
358
it('should not support multiple components or scalar values', () => {
359
- var message = 'Invalid prop `testProp` supplied to `testComponent`, ' +
360
- 'expected a single ReactElement.';
361
- typeCheckFail(PropTypes.element, [<div />, <div />], message);
362
- typeCheckFail(PropTypes.element, 123, message);
363
- typeCheckFail(PropTypes.element, 'foo', message);
364
- typeCheckFail(PropTypes.element, false, message);
359
+ typeCheckFail(
360
+ PropTypes.element,
361
+ [<div />, <div />],
362
+ 'Invalid prop `testProp` of type `array` supplied to `testComponent`, ' +
363
+ 'expected a single ReactElement.'
364
+ );
365
+ typeCheckFail(
366
+ PropTypes.element,
367
+ 123,
368
+ 'Invalid prop `testProp` of type `number` supplied to `testComponent`, ' +
369
+ 'expected a single ReactElement.'
370
+ );
371
+ typeCheckFail(
372
+ PropTypes.element,
373
+ 'foo',
374
+ 'Invalid prop `testProp` of type `string` supplied to `testComponent`, ' +
375
+ 'expected a single ReactElement.'
376
+ );
377
+ typeCheckFail(
378
+ PropTypes.element,
379
+ false,
380
+ 'Invalid prop `testProp` of type `boolean` supplied to `testComponent`, ' +
381
+ 'expected a single ReactElement.'
382
+ );
383
});
384
385
it('should be able to define a single child as label', () => {