Skip to content

Commit

Permalink
Add test for warning for camelCased unknown props
Browse files Browse the repository at this point in the history
**what is the change?:**
When we render unknown props, they get converted to lower-case.

This may be unexpected for people, or break what they are expecting to
happen. Let's warn in this case and ask them to explicitly pass the
lower-cased attribute name.

**why make this change?:**
To avoid corner case buggy results for users.

**test plan:**
NOTE: ~~~It does NOT pass right now. This is a known issue.
Should we change and just expect a warning, but allow the attribute
value to be set?

`yarn run test src/renderers/dom/shared/__tests__/ReactDOMAttribute-test.js`

**issue:** facebook#10399
  • Loading branch information
flarnie committed Sep 5, 2017
1 parent 47d8702 commit 76cc4c9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/renderers/dom/shared/__tests__/ReactDOMAttribute-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,20 @@ describe('ReactDOM unknown attribute', () => {
);
expectDev(console.error.calls.count()).toBe(1);
});

it('removes camelCased unknown props and warns', () => {
spyOn(console, 'error');

var el = document.createElement('div');
ReactDOM.render(<div hELLo="something" />, el);
expect(el.firstChild.hasAttribute('hELLo')).toBe(false);
expect(el.firstChild.hasAttribute('hello')).toBe(false);

expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
'Warning: Invalid prop `hELLo` on <div> tag. Did you mean `hello`?' +
' in div (at **)',
);
expectDev(console.error.calls.count()).toBe(1);
});
});
});

0 comments on commit 76cc4c9

Please sign in to comment.