From 6a525fdc4c90303c4e14c3aee26f8faa50e77c27 Mon Sep 17 00:00:00 2001 From: hkal Date: Sat, 3 Sep 2016 19:48:23 -0400 Subject: [PATCH] Add unknown property warning for use of (#6461) --- .../dom/shared/HTMLDOMPropertyConfig.js | 3 ++- .../shared/__tests__/ReactDOMComponent-test.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/renderers/dom/shared/HTMLDOMPropertyConfig.js b/src/renderers/dom/shared/HTMLDOMPropertyConfig.js index ec288be9ea..6d2f5a1336 100644 --- a/src/renderers/dom/shared/HTMLDOMPropertyConfig.js +++ b/src/renderers/dom/shared/HTMLDOMPropertyConfig.js @@ -41,7 +41,7 @@ var HTMLDOMPropertyConfig = { async: HAS_BOOLEAN_VALUE, autoComplete: 0, // autoFocus is polyfilled/normalized by AutoFocusUtils - // autoFocus: HAS_BOOLEAN_VALUE, + autoFocus: HAS_BOOLEAN_VALUE, autoPlay: HAS_BOOLEAN_VALUE, capture: HAS_BOOLEAN_VALUE, cellPadding: 0, @@ -205,6 +205,7 @@ var HTMLDOMPropertyConfig = { }, DOMAttributeNames: { acceptCharset: 'accept-charset', + autoFocus: 'autofocus', className: 'class', htmlFor: 'for', httpEquiv: 'http-equiv', diff --git a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js index e9cb267da9..d016cf25ee 100644 --- a/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js +++ b/src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js @@ -1495,5 +1495,22 @@ describe('ReactDOMComponent', function() { //since hard coding the line number would make test too brittle expect(parseInt(previousLine, 10) + 12).toBe(parseInt(currentLine, 10)); }); + + it('should suggest property name if available', () => { + spyOn(console, 'error'); + + ReactTestUtils.renderIntoDocument(React.createElement('label', {for: 'test'})); + ReactTestUtils.renderIntoDocument(React.createElement('input', {type: 'text', autofocus: true})); + + expect(console.error.calls.count()).toBe(2); + + expect(console.error.calls.argsFor(0)[0]).toBe( + 'Warning: Unknown DOM property for. Did you mean htmlFor?\n in label' + ); + + expect(console.error.calls.argsFor(1)[0]).toBe( + 'Warning: Unknown DOM property autofocus. Did you mean autoFocus?\n in input' + ); + }); }); });