@@ -78,21 +78,19 @@ describe('ReactDOMComponentTree', () => {
78
78
expect ( renderAndGetRef ( 'input' ) ) . toBe ( 'INPUT' ) ;
79
79
} ) ;
80
80
81
- it ( 'finds closest instance for node when an event happens' , done => {
81
+ it ( 'finds closest instance for node when an event happens' , ( ) => {
82
82
const elemID = 'aID' ;
83
83
const innerHTML = { __html : `<div id="${ elemID } "></div>` } ;
84
-
84
+ const testID = 'closestInstance' ;
85
+ let currentTargetID = null ;
85
86
class ClosestInstance extends React . Component {
86
- id = 'closestInstance' ;
87
87
_onClick = e => {
88
- const node = e . currentTarget ;
89
- expect ( node . id ) . toBe ( this . id ) ;
90
- done ( ) ;
88
+ currentTargetID = e . currentTarget . id ;
91
89
} ;
92
90
render ( ) {
93
91
return (
94
92
< div
95
- id = "closestInstance"
93
+ id = { testID }
96
94
onClick = { this . _onClick }
97
95
dangerouslySetInnerHTML = { innerHTML }
98
96
/>
@@ -104,41 +102,20 @@ describe('ReactDOMComponentTree', () => {
104
102
const container = document . createElement ( 'div' ) ;
105
103
ReactDOM . render ( < section > { component } </ section > , container ) ;
106
104
document . body . appendChild ( container ) ;
105
+ expect ( currentTargetID ) . toBe ( null ) ;
107
106
simulateClick ( document . getElementById ( elemID ) ) ;
107
+ expect ( currentTargetID ) . toBe ( testID ) ;
108
108
} ) ;
109
109
110
- it ( 'finds a controlled instance from node and gets its current fiber props' , done => {
110
+ it ( 'finds a controlled instance from node and gets its current fiber props' , ( ) => {
111
111
const inputID = 'inputID' ;
112
112
const startValue = undefined ;
113
113
const finishValue = 'finish' ;
114
114
115
115
class Controlled extends React . Component {
116
116
state = { value : startValue } ;
117
117
a = null ;
118
- _onChange = e => {
119
- const node = e . currentTarget ;
120
- expect ( node . value ) . toEqual ( finishValue ) ;
121
- expect ( node . id ) . toBe ( inputID ) ;
122
- spyOn ( console , 'error' ) ;
123
- expectDev ( console . error . calls . count ( ) ) . toBe ( 0 ) ;
124
- this . setState (
125
- {
126
- value : node . value ,
127
- } ,
128
- ( ) => {
129
- expectDev ( console . error . calls . count ( ) ) . toBe ( 1 ) ;
130
- expectDev ( console . error . calls . argsFor ( 0 ) [ 0 ] ) . toContain (
131
- 'Warning: A component is changing an uncontrolled input of ' +
132
- 'type text to be controlled. Input elements should not ' +
133
- 'switch from uncontrolled to controlled (or vice versa). ' +
134
- 'Decide between using a controlled or uncontrolled input ' +
135
- 'element for the lifetime of the component. More info: ' +
136
- 'https://fb.me/react-controlled-components' ,
137
- ) ;
138
- done ( ) ;
139
- } ,
140
- ) ;
141
- } ;
118
+ _onChange = e => this . setState ( { value : e . currentTarget . value } ) ;
142
119
render ( ) {
143
120
return (
144
121
< input
@@ -156,7 +133,19 @@ describe('ReactDOMComponentTree', () => {
156
133
const container = document . createElement ( 'div' ) ;
157
134
const instance = ReactDOM . render ( component , container ) ;
158
135
document . body . appendChild ( container ) ;
136
+ spyOn ( console , 'error' ) ;
137
+ expectDev ( console . error . calls . count ( ) ) . toBe ( 0 ) ;
159
138
simulateInput ( instance . a , finishValue ) ;
139
+ expectDev ( console . error . calls . count ( ) ) . toBe ( 1 ) ;
140
+ expectDev ( console . error . calls . argsFor ( 0 ) [ 0 ] ) . toContain (
141
+ 'Warning: A component is changing an uncontrolled input of ' +
142
+ 'type text to be controlled. Input elements should not ' +
143
+ 'switch from uncontrolled to controlled (or vice versa). ' +
144
+ 'Decide between using a controlled or uncontrolled input ' +
145
+ 'element for the lifetime of the component. More info: ' +
146
+ 'https://fb.me/react-controlled-components' ,
147
+ ) ;
148
+
160
149
} ) ;
161
150
162
151
it ( 'finds instance of node that is attempted to be unmounted' , ( ) => {
0 commit comments