Add test to ensure checked inputs don't accidentally get value="on" (#12000)
In absence of a value, radio and checkboxes report a value of "on". Between 16 and 16.2, we assigned a node's value to it's current value in order to "dettach" it from defaultValue. This had the unfortunate side-effect of assigning value="on" to radio and checkboxes Related issues: https://github.com/facebook/react/issues/11998
Nathan Hunzaker committed
Jan 9, 2018 at 18:45 UTC
982a82884493c39f3cf322734ada175b6fb6bf22
1 file changed
+27
packages/react-dom/src/__tests__/ReactDOMInput-test.js
+27
@@ -1674,4 +1674,31 @@ describe('ReactDOMInput', () => {
1674
// TODO: we should warn here.
1675
});
1676
});
1677
+
1678
+ describe('checked inputs without a value property', function() {
1679
+ // In absence of a value, radio and checkboxes report a value of "on".
1680
+ // Between 16 and 16.2, we assigned a node's value to it's current
1681
+ // value in order to "dettach" it from defaultValue. This had the unfortunate
1682
+ // side-effect of assigning value="on" to radio and checkboxes
1683
+ it('does not add "on" in absence of value on a checkbox', function() {
1684
+ const container = document.createElement('div');
1685
+ ReactDOM.render(
1686
+ <input type="checkbox" defaultChecked={true} />,
1687
+ container,
1688
+ );
1689
+ const node = container.firstChild;
1690
+
1691
+ expect(node.value).toBe('on');
1692
+ expect(node.hasAttribute('value')).toBe(false);
1693
+ });
1694
+
1695
+ it('does not add "on" in absence of value on a radio', function() {
1696
+ const container = document.createElement('div');
1697
+ ReactDOM.render(<input type="radio" defaultChecked={true} />, container);
1698
+ const node = container.firstChild;
1699
+
1700
+ expect(node.value).toBe('on');
1701
+ expect(node.hasAttribute('value')).toBe(false);
1702
+ });
1703
+ });
1704
});