@@ -33,15 +33,6 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
33
33
document . body . removeChild ( container ) ;
34
34
} ) ;
35
35
36
- function dispatchAndSetCurrentEvent ( el , event ) {
37
- try {
38
- window . event = event ;
39
- el . dispatchEvent ( event ) ;
40
- } finally {
41
- window . event = undefined ;
42
- }
43
- }
44
-
45
36
// @gate experimental
46
37
// @gate enableDiscreteEventMicroTasks && enableNativeEventPriorityInference
47
38
it ( 'ignores discrete events on a pending removed element' , async ( ) => {
@@ -78,9 +69,9 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
78
69
// Dispatch a click event on the Disable-button.
79
70
const firstEvent = document . createEvent ( 'Event' ) ;
80
71
firstEvent . initEvent ( 'click' , true , true ) ;
81
- expect ( ( ) =>
82
- dispatchAndSetCurrentEvent ( disableButton , firstEvent ) ,
83
- ) . toErrorDev ( [ 'An update to Form inside a test was not wrapped in act' ] ) ;
72
+ expect ( ( ) => disableButton . dispatchEvent ( firstEvent ) ) . toErrorDev ( [
73
+ 'An update to Form inside a test was not wrapped in act' ,
74
+ ] ) ;
84
75
85
76
// There should now be a pending update to disable the form.
86
77
// This should not have flushed yet since it's in concurrent mode.
@@ -144,7 +135,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
144
135
const firstEvent = document . createEvent ( 'Event' ) ;
145
136
firstEvent . initEvent ( 'click' , true , true ) ;
146
137
expect ( ( ) => {
147
- dispatchAndSetCurrentEvent ( disableButton , firstEvent ) ;
138
+ disableButton . dispatchEvent ( firstEvent ) ;
148
139
} ) . toErrorDev ( [ 'An update to Form inside a test was not wrapped in act' ] ) ;
149
140
150
141
// There should now be a pending update to disable the form.
@@ -158,7 +149,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
158
149
// Now let's dispatch an event on the submit button.
159
150
const secondEvent = document . createEvent ( 'Event' ) ;
160
151
secondEvent . initEvent ( 'click' , true , true ) ;
161
- dispatchAndSetCurrentEvent ( submitButton , secondEvent ) ;
152
+ submitButton . dispatchEvent ( secondEvent ) ;
162
153
163
154
// Therefore the form should never have been submitted.
164
155
expect ( formSubmitted ) . toBe ( false ) ;
@@ -208,7 +199,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
208
199
const firstEvent = document . createEvent ( 'Event' ) ;
209
200
firstEvent . initEvent ( 'click' , true , true ) ;
210
201
expect ( ( ) => {
211
- dispatchAndSetCurrentEvent ( enableButton , firstEvent ) ;
202
+ enableButton . dispatchEvent ( firstEvent ) ;
212
203
} ) . toErrorDev ( [ 'An update to Form inside a test was not wrapped in act' ] ) ;
213
204
214
205
// There should now be a pending update to enable the form.
@@ -222,7 +213,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
222
213
// Now let's dispatch an event on the submit button.
223
214
const secondEvent = document . createEvent ( 'Event' ) ;
224
215
secondEvent . initEvent ( 'click' , true , true ) ;
225
- dispatchAndSetCurrentEvent ( submitButton , secondEvent ) ;
216
+ submitButton . dispatchEvent ( secondEvent ) ;
226
217
227
218
// Therefore the form should have been submitted.
228
219
expect ( formSubmitted ) . toBe ( true ) ;
@@ -250,7 +241,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
250
241
await act ( async ( ) => {
251
242
const mouseOverEvent = document . createEvent ( 'MouseEvents' ) ;
252
243
mouseOverEvent . initEvent ( 'mouseover' , true , true ) ;
253
- dispatchAndSetCurrentEvent ( target . current , mouseOverEvent ) ;
244
+ target . current . dispatchEvent ( mouseOverEvent ) ;
254
245
255
246
// 3s should be enough to expire the updates
256
247
Scheduler . unstable_advanceTime ( 3000 ) ;
@@ -283,7 +274,7 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
283
274
// but we should still correctly determine their priority.
284
275
const mouseEnterEvent = document . createEvent ( 'MouseEvents' ) ;
285
276
mouseEnterEvent . initEvent ( 'mouseenter' , true , true ) ;
286
- dispatchAndSetCurrentEvent ( target . current , mouseEnterEvent ) ;
277
+ target . current . dispatchEvent ( mouseEnterEvent ) ;
287
278
288
279
// 3s should be enough to expire the updates
289
280
Scheduler . unstable_advanceTime ( 3000 ) ;
0 commit comments