Skip to content

Commit

Permalink
Reword messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
chenglou committed Jul 26, 2016
1 parent c73eb22 commit d4105cd
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 29 deletions.
21 changes: 12 additions & 9 deletions src/addons/link/__tests__/ReactLinkPropTypes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ var ReactPropTypeLocations = require('ReactPropTypeLocations');
var ReactPropTypesSecret = require('ReactPropTypesSecret');

var invalidMessage = 'Invalid prop `testProp` supplied to `testComponent`.';
var requiredMessage =
'Required prop `testProp` was not specified in `testComponent`.';
var requiredMessage = 'The prop `testProp` is marked as required in ' +
'`testComponent`, but its value is `undefined`.';

function typeCheckFail(declaration, value, message) {
var props = {testProp: value};
Expand Down Expand Up @@ -53,23 +53,26 @@ describe('ReactLink', function() {
typeCheckFail(
LinkPropTypes.link(React.PropTypes.any),
{},
'Required prop `testProp.value` was not specified in `testComponent`.'
'The prop `testProp.value` is marked as required in `testComponent`, ' +
'but its value is `undefined`.'
);
typeCheckFail(
LinkPropTypes.link(React.PropTypes.any),
{value: 123},
'Required prop `testProp.requestChange` was not specified in `testComponent`.'
'The prop `testProp.requestChange` is marked as required in ' +
'`testComponent`, but its value is `undefined`.'
);
typeCheckFail(
LinkPropTypes.link(React.PropTypes.any),
{requestChange: emptyFunction},
'Required prop `testProp.value` was not specified in `testComponent`.'
'The prop `testProp.value` is marked as required in `testComponent`, ' +
'but its value is `undefined`.'
);
typeCheckFail(
LinkPropTypes.link(React.PropTypes.any),
{value: null, requestChange: null},
'Required prop `testProp.value` was specified in `testComponent`, but ' +
'its value is `null`.'
'The prop `testProp.value` is marked as required in `testComponent`, ' +
'but its value is `null`.'
);
});

Expand Down Expand Up @@ -123,8 +126,8 @@ describe('ReactLink', function() {
});

it('should warn for missing required values', function() {
var specifiedButIsNullMsg = 'Required prop `testProp` was specified in ' +
'`testComponent`, but its value is `null`.';
var specifiedButIsNullMsg = 'The prop `testProp` is marked as required ' +
'in `testComponent`, but its value is `null`.';
typeCheckFail(LinkPropTypes.link().isRequired, null, specifiedButIsNullMsg);
typeCheckFail(LinkPropTypes.link().isRequired, undefined, requiredMessage);
typeCheckFail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ describe('ReactContextValidator', function() {
expect(console.error.calls.count()).toBe(1);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Failed context type: ' +
'Required context `foo` was not specified in `Component`.\n' +
'The context `foo` is marked as required in `Component`, but its value ' +
'is `undefined`.\n' +
' in Component (at **)'
);

Expand Down Expand Up @@ -229,7 +230,8 @@ describe('ReactContextValidator', function() {
expect(console.error.calls.count()).toBe(1);
expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Failed childContext type: ' +
'Required child context `foo` was not specified in `Component`.\n' +
'The child context `foo` is marked as required in `Component`, but its ' +
'value is `undefined`.\n' +
' in Component (at **)'
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ describe('ReactElementValidator', function() {

expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Failed prop type: Required prop `prop` was specified in ' +
'Warning: Failed prop type: The prop `prop` is marked as required in ' +
'`Component`, but its value is `null`.\n' +
' in Component'
);
Expand All @@ -385,7 +385,7 @@ describe('ReactElementValidator', function() {

expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Failed prop type: Required prop `prop` was specified in ' +
'Warning: Failed prop type: The prop `prop` is marked as required in ' +
'`Component`, but its value is `null`.\n' +
' in Component'
);
Expand Down Expand Up @@ -413,7 +413,8 @@ describe('ReactElementValidator', function() {
expect(console.error.calls.count()).toBe(2);
expect(console.error.calls.argsFor(0)[0]).toBe(
'Warning: Failed prop type: ' +
'Required prop `prop` was not specified in `Component`.\n' +
'The prop `prop` is marked as required in `Component`, but its value ' +
'is `undefined`.\n' +
' in Component'
);

Expand Down
8 changes: 4 additions & 4 deletions src/isomorphic/classic/types/ReactPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ function createChainableTypeChecker(validate) {
if (isRequired) {
if (props[propName] === null) {
return new Error(
`Required ${locationName} \`${propFullName}\` was specified in ` +
`\`${componentName}\`, but its value is \`null\`.`
`The ${locationName} \`${propFullName}\` is marked as required ` +
`in \`${componentName}\`, but its value is \`null\`.`
);
}
return new Error(
`Required ${locationName} \`${propFullName}\` was not specified in ` +
`\`${componentName}\`.`
`The ${locationName} \`${propFullName}\` is marked as required in ` +
`\`${componentName}\`, but its value is \`undefined\`.`
);
}
return null;
Expand Down
14 changes: 8 additions & 6 deletions src/isomorphic/classic/types/__tests__/ReactPropTypes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ function typeCheckFail(declaration, value, message) {
}

function typeCheckFailRequiredValues(declaration) {
var specifiedButIsNullMsg = 'Required prop `testProp` was specified in ' +
'`testComponent`, but its value is `null`.';
var unspecifiedMsg =
'Required prop `testProp` was not specified in `testComponent`.';
var specifiedButIsNullMsg = 'The prop `testProp` is marked as required in ' +
'`testComponent`, but its value is `null`.';
var unspecifiedMsg = 'The prop `testProp` is marked as required in ' +
'`testComponent`, but its value is \`undefined\`.';
var props1 = {testProp: null};
var error1 = declaration(
props1,
Expand Down Expand Up @@ -941,7 +941,8 @@ describe('ReactPropTypes', function() {
typeCheckFail(
PropTypes.shape({key: PropTypes.number.isRequired}),
{},
'Required prop `testProp.key` was not specified in `testComponent`.'
'The prop `testProp.key` is marked as required in `testComponent`, ' +
'but its value is `undefined`.'
);
});

Expand All @@ -952,7 +953,8 @@ describe('ReactPropTypes', function() {
secondKey: PropTypes.number.isRequired,
}),
{},
'Required prop `testProp.key` was not specified in `testComponent`.'
'The prop `testProp.key` is marked as required in `testComponent`, ' +
'but its value is `undefined`.'
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ describe('ReactJSXElementValidator', function() {
expect(
console.error.calls.argsFor(0)[0].replace(/\(at .+?:\d+\)/g, '(at **)')
).toBe(
'Warning: Failed prop type: Required prop `prop` was specified in ' +
'Warning: Failed prop type: The prop `prop` is marked as required in ' +
'`RequiredPropComponent`, but its value is `null`.\n' +
' in RequiredPropComponent (at **)'
);
Expand All @@ -264,7 +264,7 @@ describe('ReactJSXElementValidator', function() {
expect(
console.error.calls.argsFor(0)[0].replace(/\(at .+?:\d+\)/g, '(at **)')
).toBe(
'Warning: Failed prop type: Required prop `prop` was specified in ' +
'Warning: Failed prop type: The prop `prop` is marked as required in ' +
'`RequiredPropComponent`, but its value is `null`.\n' +
' in RequiredPropComponent (at **)'
);
Expand All @@ -281,7 +281,8 @@ describe('ReactJSXElementValidator', function() {
console.error.calls.argsFor(0)[0].replace(/\(at .+?:\d+\)/g, '(at **)')
).toBe(
'Warning: Failed prop type: ' +
'Required prop `prop` was not specified in `RequiredPropComponent`.\n' +
'The prop `prop` is marked as required in `RequiredPropComponent`, but ' +
'its value is `undefined`.\n' +
' in RequiredPropComponent (at **)'
);

Expand Down
4 changes: 2 additions & 2 deletions src/test/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ describe('ReactTestUtils', function() {
expect(
console.error.calls.argsFor(0)[0].replace(/\(at .+?:\d+\)/g, '(at **)')
).toBe(
'Warning: Failed context type: Required context `name` was not ' +
'specified in `SimpleComponent`.\n' +
'Warning: Failed context type: The context `name` is marked as ' +
'required in `SimpleComponent`, but its value is `undefined`.\n' +
' in SimpleComponent (at **)'
);
});
Expand Down

0 comments on commit d4105cd

Please sign in to comment.