Skip to content

Commit

Permalink
Modified tests and corrected error message. #3
Browse files Browse the repository at this point in the history
  • Loading branch information
NicBonetto committed Oct 20, 2017
1 parent 97776fb commit 2653595
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
16 changes: 12 additions & 4 deletions packages/react-dom/src/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2042,7 +2042,9 @@ describe('ReactDOMComponent', () => {
expect(el.hasAttribute('whatever')).toBe(false);

expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Warning: Received `true` for non-boolean attribute `whatever`',
'If you intentionally tried to pass a boolean, pass it as a string ' +
'instead: trues="`whatever`". If you mean to conditionally pass an ' +
'attribute, use a ternary expression: `true`={condition ? value : null}.',
);
});

Expand All @@ -2055,7 +2057,9 @@ describe('ReactDOMComponent', () => {
expect(el.hasAttribute('whatever')).toBe(false);

expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Warning: Received `true` for non-boolean attribute `whatever`',
'If you intentionally tried to pass a boolean, pass it as a string ' +
'instead: `true`="`whatever`". If you mean to conditionally pass an ' +
'attribute, use a ternary expression: `true`={condition ? value : null}.',
);
});

Expand Down Expand Up @@ -2230,7 +2234,9 @@ describe('ReactDOMComponent', () => {
expect(el.hasAttribute('whatever')).toBe(false);

expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Warning: Received `true` for non-boolean attribute `whatever`.',
'If you intentionally tried to pass a boolean, pass it as a string ' +
'instead: `true`="`whatever`". If you mean to conditionally pass an ' +
'attribute, use a ternary expression: `true`={condition ? value : null}.',
);
});

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

expectDev(console.error.calls.count()).toBe(1);
expectDev(console.error.calls.argsFor(0)[0]).toContain(
'Warning: Received `false` for non-boolean attribute `whatever`.',
'If you intentionally tried to pass a boolean, pass it as a string ' +
'instead: `false`="`whatever`". If you mean to conditionally pass an ' +
'attribute, use a ternary expression: `false`={condition ? value : null}.',
);
});
});
Expand Down
6 changes: 4 additions & 2 deletions packages/react-dom/src/shared/ReactDOMUnknownPropertyHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,12 @@ if (__DEV__) {
if (typeof value === 'boolean') {
warning(
DOMProperty.shouldAttributeAcceptBooleanValue(name),
'Received `%s` for non-boolean attribute `%s`. If this is expected, cast ' +
'the value to a string.%s',
'If you intentionally tried to pass a boolean, pass it as a string ' +
'instead: `%s`="`%s`". If you mean to conditionally pass an ' +
'attribute, use a ternary expression: `%s`={condition ? value : null}.%s',
value,
name,
value,
getStackAddendum(),
);
warnedProperties[name] = true;
Expand Down

0 comments on commit 2653595

Please sign in to comment.