@@ -258,4 +258,37 @@ describe('ReactDOMNativeEventHeuristic-test', () => {
258
258
expect ( container . textContent ) . toEqual ( 'hovered' ) ;
259
259
} ) ;
260
260
} ) ;
261
+
262
+ // @gate experimental
263
+ // @gate enableDiscreteEventMicroTasks && enableNativeEventPriorityInference
264
+ it ( 'mouse enter should be user-blocking but not discrete' , async ( ) => {
265
+ const root = ReactDOM . unstable_createRoot ( container ) ;
266
+
267
+ const target = React . createRef ( null ) ;
268
+ function Foo ( ) {
269
+ const [ isHover , setHover ] = React . useState ( false ) ;
270
+ React . useLayoutEffect ( ( ) => {
271
+ target . current . onmouseenter = ( ) => setHover ( true ) ;
272
+ } ) ;
273
+ return < div ref = { target } > { isHover ? 'hovered' : 'not hovered' } </ div > ;
274
+ }
275
+
276
+ await act ( async ( ) => {
277
+ root . render ( < Foo /> ) ;
278
+ } ) ;
279
+ expect ( container . textContent ) . toEqual ( 'not hovered' ) ;
280
+
281
+ await act ( async ( ) => {
282
+ // Note: React does not use native mouseenter/mouseleave events
283
+ // but we should still correctly determine their priority.
284
+ const mouseEnterEvent = document . createEvent ( 'MouseEvents' ) ;
285
+ mouseEnterEvent . initEvent ( 'mouseenter' , true , true ) ;
286
+ dispatchAndSetCurrentEvent ( target . current , mouseEnterEvent ) ;
287
+
288
+ // 3s should be enough to expire the updates
289
+ Scheduler . unstable_advanceTime ( 3000 ) ;
290
+ expect ( Scheduler ) . toFlushExpired ( [ ] ) ;
291
+ expect ( container . textContent ) . toEqual ( 'hovered' ) ;
292
+ } ) ;
293
+ } ) ;
261
294
} ) ;
0 commit comments