mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Add unknown property warning for use of autofocus (#7694)
This commit is contained in:
@@ -193,9 +193,13 @@ var DOMProperty = {
|
||||
/**
|
||||
* Mapping from lowercase property names to the properly cased version, used
|
||||
* to warn in the case of missing properties. Available only in __DEV__.
|
||||
*
|
||||
* autofocus is predefined, because adding it to the property whitelist
|
||||
* causes unintended side effects.
|
||||
*
|
||||
* @type {Object}
|
||||
*/
|
||||
getPossibleStandardName: __DEV__ ? {} : null,
|
||||
getPossibleStandardName: __DEV__ ? {autofocus: 'autoFocus'} : null,
|
||||
|
||||
/**
|
||||
* All of the isCustomAttribute() functions that have been injected.
|
||||
|
||||
@@ -1495,5 +1495,22 @@ describe('ReactDOMComponent', () => {
|
||||
//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'
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user