|
11 | 11 | 'use strict'; |
12 | 12 |
|
13 | 13 | var React = require('React'); |
| 14 | +var ReactDOM = require('ReactDOM'); |
14 | 15 | var ReactTestUtils = require('ReactTestUtils'); |
15 | 16 | var inputValueTracking = require('inputValueTracking'); |
16 | 17 |
|
@@ -143,16 +144,38 @@ describe('inputValueTracking', function() { |
143 | 144 | it('should stop tracking', function() { |
144 | 145 | inputValueTracking.track(mockComponent); |
145 | 146 |
|
146 | | - expect(mockComponent._wrapperState.hasOwnProperty('valueTracker')).toBe( |
147 | | - true, |
148 | | - ); |
| 147 | + expect(mockComponent._wrapperState.valueTracker).not.toEqual(null); |
149 | 148 |
|
150 | 149 | inputValueTracking.stopTracking(mockComponent); |
151 | 150 |
|
152 | | - expect(mockComponent._wrapperState.hasOwnProperty('valueTracker')).toBe( |
153 | | - false, |
154 | | - ); |
| 151 | + expect(mockComponent._wrapperState.valueTracker).toEqual(null); |
155 | 152 |
|
156 | 153 | expect(input.hasOwnProperty('value')).toBe(false); |
157 | 154 | }); |
| 155 | + |
| 156 | + it('does not crash for nodes with custom value property', () => { |
| 157 | + // https://github.com/facebook/react/issues/10196 |
| 158 | + try { |
| 159 | + var originalCreateElement = document.createElement; |
| 160 | + document.createElement = function() { |
| 161 | + var node = originalCreateElement.apply(this, arguments); |
| 162 | + Object.defineProperty(node, 'value', { |
| 163 | + get() {}, |
| 164 | + set() {}, |
| 165 | + }); |
| 166 | + return node; |
| 167 | + }; |
| 168 | + var div = document.createElement('div'); |
| 169 | + // Mount |
| 170 | + var node = ReactDOM.render(<input type="text" />, div); |
| 171 | + // Update |
| 172 | + ReactDOM.render(<input type="text" />, div); |
| 173 | + // Change |
| 174 | + ReactTestUtils.SimulateNative.change(node); |
| 175 | + // Unmount |
| 176 | + ReactDOM.unmountComponentAtNode(div); |
| 177 | + } finally { |
| 178 | + document.createElement = originalCreateElement; |
| 179 | + } |
| 180 | + }); |
158 | 181 | }); |
0 commit comments