248
}
249
});
250
251
+ it('performs a state change from "" to 0', () => {
252
+ class Stub extends React.Component {
253
+ state = {
254
+ value: '',
255
+ };
256
+ render() {
257
+ return <input type="number" value={this.state.value} readOnly={true} />;
258
+ }
259
+ }
260
+
261
+ var stub = ReactTestUtils.renderIntoDocument(<Stub />);
262
+ var node = ReactDOM.findDOMNode(stub);
263
+ stub.setState({value: 0});
264
+
265
+ expect(node.value).toEqual('0');
266
+ });
267
+
268
it('distinguishes precision for extra zeroes in string number values', () => {
269
spyOnDev(console, 'error');
270
class Stub extends React.Component {
612
var node = container.firstChild;
613
614
expect(node.value).toBe('0');
615
+ expect(node.defaultValue).toBe('0');
616
});
617
618
it('should properly transition from 0 to an empty value', function() {
624
var node = container.firstChild;
625
626
expect(node.value).toBe('');
627
+ expect(node.defaultValue).toBe('');
628
+ });
629
+
630
+ it('should properly transition a text input from 0 to an empty 0.0', function() {
631
+ var container = document.createElement('div');
632
+
633
+ ReactDOM.render(<input type="text" value={0} />, container);
634
+ ReactDOM.render(<input type="text" value="0.0" />, container);
635
+
636
+ var node = container.firstChild;
637
+
638
+ expect(node.value).toBe('0.0');
639
+ expect(node.defaultValue).toBe('0.0');
640
+ });
641
+
642
+ it('should properly transition a number input from "" to 0', function() {
643
+ var container = document.createElement('div');
644
+
645
+ ReactDOM.render(<input type="number" value="" />, container);
646
+ ReactDOM.render(<input type="number" value={0} />, container);
647
+
648
+ var node = container.firstChild;
649
+
650
+ expect(node.value).toBe('0');
651
+ expect(node.defaultValue).toBe('0');
652
+ });
653
+
654
+ it('should properly transition a number input from "" to "0"', function() {
655
+ var container = document.createElement('div');
656
+
657
+ ReactDOM.render(<input type="number" value="" />, container);
658
+ ReactDOM.render(<input type="number" value="0" />, container);
659
+
660
+ var node = container.firstChild;
661
+
662
+ expect(node.value).toBe('0');
663
+ expect(node.defaultValue).toBe('0');
664
});
665
666
it('should have the correct target value', () => {
1640
}
1641
});
1642
});
1643
+
1644
+ describe('When given a Symbol value', function() {
1645
+ it('treats initial Symbol value as an empty string', function() {
1646
+ spyOnDev(console, 'error');
1647
+ var container = document.createElement('div');
1648
+ ReactDOM.render(
1649
+ <input value={Symbol('foobar')} onChange={() => {}} />,
1650
+ container,
1651
+ );
1652
+ var node = container.firstChild;
1653
+
1654
+ expect(node.value).toBe('');
1655
+ expect(node.getAttribute('value')).toBe('');
1656
+
1657
+ if (__DEV__) {
1658
+ expect(console.error.calls.count()).toBe(1);
1659
+ expect(console.error.calls.argsFor(0)[0]).toContain(
1660
+ 'Invalid value for prop `value`',
1661
+ );
1662
+ }
1663
+ });
1664
+
1665
+ it('treats updated Symbol value as an empty string', function() {
1666
+ spyOnDev(console, 'error');
1667
+ var container = document.createElement('div');
1668
+ ReactDOM.render(<input value="foo" onChange={() => {}} />, container);
1669
+ ReactDOM.render(
1670
+ <input value={Symbol('foobar')} onChange={() => {}} />,
1671
+ container,
1672
+ );
1673
+ var node = container.firstChild;
1674
+
1675
+ expect(node.value).toBe('');
1676
+ expect(node.getAttribute('value')).toBe('');
1677
+
1678
+ if (__DEV__) {
1679
+ expect(console.error.calls.count()).toBe(1);
1680
+ expect(console.error.calls.argsFor(0)[0]).toContain(
1681
+ 'Invalid value for prop `value`',
1682
+ );
1683
+ }
1684
+ });
1685
+
1686
+ it('treats initial Symbol defaultValue as an empty string', function() {
1687
+ var container = document.createElement('div');
1688
+ ReactDOM.render(<input defaultValue={Symbol('foobar')} />, container);
1689
+ var node = container.firstChild;
1690
+
1691
+ expect(node.value).toBe('');
1692
+ expect(node.getAttribute('value')).toBe('');
1693
+ // TODO: we should warn here.
1694
+ });
1695
+
1696
+ it('treats updated Symbol defaultValue as an empty string', function() {
1697
+ var container = document.createElement('div');
1698
+ ReactDOM.render(<input defaultValue="foo" />, container);
1699
+ ReactDOM.render(<input defaultValue={Symbol('foobar')} />, container);
1700
+ var node = container.firstChild;
1701
+
1702
+ expect(node.value).toBe('foo');
1703
+ expect(node.getAttribute('value')).toBe('');
1704
+ // TODO: we should warn here.
1705
+ });
1706
+ });
1707
+
1708
+ describe('When given a function value', function() {
1709
+ it('treats initial function value as an empty string', function() {
1710
+ spyOnDev(console, 'error');
1711
+ var container = document.createElement('div');
1712
+ ReactDOM.render(
1713
+ <input value={() => {}} onChange={() => {}} />,
1714
+ container,
1715
+ );
1716
+ var node = container.firstChild;
1717
+
1718
+ expect(node.value).toBe('');
1719
+ expect(node.getAttribute('value')).toBe('');
1720
+
1721
+ if (__DEV__) {
1722
+ expect(console.error.calls.count()).toBe(1);
1723
+ expect(console.error.calls.argsFor(0)[0]).toContain(
1724
+ 'Invalid value for prop `value`',
1725
+ );
1726
+ }
1727
+ });
1728
+
1729
+ it('treats updated function value as an empty string', function() {
1730
+ spyOnDev(console, 'error');
1731
+ var container = document.createElement('div');
1732
+ ReactDOM.render(<input value="foo" onChange={() => {}} />, container);
1733
+ ReactDOM.render(
1734
+ <input value={() => {}} onChange={() => {}} />,
1735
+ container,
1736
+ );
1737
+ var node = container.firstChild;
1738
+
1739
+ expect(node.value).toBe('');
1740
+ expect(node.getAttribute('value')).toBe('');
1741
+
1742
+ if (__DEV__) {
1743
+ expect(console.error.calls.count()).toBe(1);
1744
+ expect(console.error.calls.argsFor(0)[0]).toContain(
1745
+ 'Invalid value for prop `value`',
1746
+ );
1747
+ }
1748
+ });
1749
+
1750
+ it('treats initial function defaultValue as an empty string', function() {
1751
+ var container = document.createElement('div');
1752
+ ReactDOM.render(<input defaultValue={() => {}} />, container);
1753
+ var node = container.firstChild;
1754
+
1755
+ expect(node.value).toBe('');
1756
+ expect(node.getAttribute('value')).toBe('');
1757
+ // TODO: we should warn here.
1758
+ });
1759
+
1760
+ it('treats updated function defaultValue as an empty string', function() {
1761
+ var container = document.createElement('div');
1762
+ ReactDOM.render(<input defaultValue="foo" />, container);
1763
+ ReactDOM.render(<input defaultValue={() => {}} />, container);
1764
+ var node = container.firstChild;
1765
+
1766
+ expect(node.value).toBe('foo');
1767
+ expect(node.getAttribute('value')).toBe('');
1768
+ // TODO: we should warn here.
1769
+ });
1770
+ });
1771
});