diff --git a/packages/react-dom/src/__tests__/ReactDOMAttribute-test.js b/packages/react-dom/src/__tests__/ReactDOMAttribute-test.js index dca6ef23ab..67589233e9 100644 --- a/packages/react-dom/src/__tests__/ReactDOMAttribute-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMAttribute-test.js @@ -54,8 +54,9 @@ 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' + + 'Received `true` for a non-boolean attribute `unknown`.\n\n' + + 'If you want to write it to the DOM, pass a string instead: ' + + 'unknown="true" or unknown={value.toString()}.\n' + ' in div (at **)', ); expectDev(console.error.calls.count()).toBe(1); @@ -87,7 +88,7 @@ describe('ReactDOM unknown attribute', () => { expectDev( normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]), ).toMatch( - 'Warning: Received NaN for numeric attribute `unknown`. ' + + 'Warning: Received NaN for the `unknown` attribute. ' + 'If this is expected, cast the value to a string.\n' + ' in div (at **)', ); diff --git a/packages/react-dom/src/__tests__/ReactDOMComponent-test.js b/packages/react-dom/src/__tests__/ReactDOMComponent-test.js index b0f205a148..58e7b89ec8 100644 --- a/packages/react-dom/src/__tests__/ReactDOMComponent-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMComponent-test.js @@ -714,7 +714,7 @@ describe('ReactDOMComponent', () => { expectDev(console.error.calls.count()).toBe(1); expectDev(console.error.calls.argsFor(0)[0]).toContain( - 'Received a `function` for string attribute `is`. If this is expected, cast ' + + 'Received a `function` for a string attribute `is`. If this is expected, cast ' + 'the value to a string.', ); }); @@ -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`', + 'Received `true` for a non-boolean attribute `whatever`.\n\n' + + 'If you want to write it to the DOM, pass a string instead: ' + + 'whatever="true" or whatever={value.toString()}.', ); }); @@ -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`', + 'Received `true` for a non-boolean attribute `whatever`.\n\n' + + 'If you want to write it to the DOM, pass a string instead: ' + + 'whatever="true" or whatever={value.toString()}.', ); }); @@ -2128,7 +2132,7 @@ describe('ReactDOMComponent', () => { expect(el.getAttribute('whatever')).toBe('NaN'); expectDev(console.error.calls.argsFor(0)[0]).toContain( - 'Warning: Received NaN for numeric attribute `whatever`. If this is ' + + 'Warning: Received NaN for the `whatever` attribute. If this is ' + 'expected, cast the value to a string.\n in div', ); }); @@ -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`.', + 'Received `true` for a non-boolean attribute `whatever`.\n\n' + + 'If you want to write it to the DOM, pass a string instead: ' + + 'whatever="true" or whatever={value.toString()}.', ); }); @@ -2283,7 +2289,11 @@ 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`.', + 'Received `false` for a non-boolean attribute `whatever`.\n\n' + + 'If you want to write it to the DOM, pass a string instead: ' + + 'whatever="false" or whatever={value.toString()}.\n\n' + + 'If you used to conditionally omit it with whatever={condition && value}, ' + + 'pass whatever={condition ? value : undefined} instead.', ); }); }); diff --git a/packages/react-dom/src/__tests__/ReactDOMFiber-test.js b/packages/react-dom/src/__tests__/ReactDOMFiber-test.js index 36f63a3b4f..d208cb5861 100644 --- a/packages/react-dom/src/__tests__/ReactDOMFiber-test.js +++ b/packages/react-dom/src/__tests__/ReactDOMFiber-test.js @@ -945,6 +945,25 @@ describe('ReactDOMFiber', () => { ); }); + it('should warn with a special message for `false` event listeners', () => { + spyOn(console, 'error'); + class Example extends React.Component { + render() { + return
; + } + } + ReactDOM.render(