Skip to content

Commit

Permalink
Refactored falsy warning message and tests. #3
Browse files Browse the repository at this point in the history
  • Loading branch information
NicBonetto committed Oct 28, 2017
1 parent e18a235 commit 9fc2b7f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/react-dom/src/__tests__/ReactDOMAttribute-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ describe('ReactDOM unknown attribute', () => {
expectDev(
normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]),
).toMatch(
'Warning: Received `true` for non-boolean attribute `unknown`. If this is expected, cast ' +
'the value to a string.\n' +
'Warning: Received `true` for non-boolean attribute `unknown`. ' +
'If this is expected, cast the value to a string.\n' +
' in div (at **)',
);
expectDev(console.error.calls.count()).toBe(1);
Expand Down
18 changes: 9 additions & 9 deletions packages/react-dom/src/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2042,8 +2042,8 @@ describe('ReactDOMComponent', () => {
expect(el.hasAttribute('whatever')).toBe(false);

expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Received `true` for non-boolean attribute `whatever`. If this is expected, cast ' +
'the value to a string.',
'Received `true` for non-boolean attribute `whatever`. ' +
'If this is expected, cast the value to a string.',
);
});

Expand All @@ -2056,8 +2056,8 @@ describe('ReactDOMComponent', () => {
expect(el.hasAttribute('whatever')).toBe(false);

expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Received `true` for non-boolean attribute `whatever`. If this is expected, cast ' +
'the value to a string.',
'Received `true` for non-boolean attribute `whatever`. ' +
'If this is expected, cast the value to a string.',
);
});

Expand Down Expand Up @@ -2232,8 +2232,8 @@ describe('ReactDOMComponent', () => {
expect(el.hasAttribute('whatever')).toBe(false);

expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Received `true` for non-boolean attribute `whatever`. If this is expected, cast ' +
'the value to a string.',
'Received `true` for non-boolean attribute `whatever`. ' +
'If this is expected, cast the value to a string.',
);
});

Expand Down Expand Up @@ -2286,9 +2286,9 @@ describe('ReactDOMComponent', () => {

expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'If you mean to conditionally pass an attribute, use a ternary ' +
'expression: `false`={condition ? value : undefined} instead of ' +
'{condition && value}.',
'Received `false` for non-boolean attribute `whatever`. If you mean to conditionally ' +
'pass an attribute, use a ternary expression: {condition ? `whatever` : undefined} ' +
'instead of {condition && `whatever`}.',
);
});
});
Expand Down
9 changes: 6 additions & 3 deletions packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,13 @@ if (__DEV__) {
} else {
warning(
false,
'If you mean to conditionally pass an attribute, use a ternary ' +
'expression: `%s`={condition ? value : undefined} instead of ' +
'{condition && value}.%s',
'Received `%s` for non-boolean attribute `%s`. If you mean to conditionally ' +
'pass an attribute, use a ternary expression: {condition ? `%s` : undefined} ' +
'instead of {condition && `%s`}.%s',
value,
name,
name,
name,
getStackAddendum(),
);
}
Expand Down

0 comments on commit 9fc2b7f

Please sign in to comment.