@@ -81,19 +81,9 @@ export class UnitTestElement implements TestElement {
81
81
const clientX = Math . round ( left + relativeX ) ;
82
82
const clientY = Math . round ( top + relativeY ) ;
83
83
84
- // The latest versions of all browsers we support have the new `PointerEvent` API.
85
- // Though since we capture the two most recent versions of these browsers, we also
86
- // need to support Safari 12 at time of writing. Safari 12 does not have support for this,
87
- // so we need to conditionally create and dispatch these events based on feature detection.
88
- const emitPointerEvents = window . PointerEvent !== undefined ;
89
-
90
- if ( emitPointerEvents ) {
91
- dispatchPointerEvent ( this . element , 'pointerdown' , clientX , clientY ) ;
92
- }
84
+ this . _dispatchPointerEventIfSupported ( 'pointerdown' , clientX , clientY ) ;
93
85
dispatchMouseEvent ( this . element , 'mousedown' , clientX , clientY ) ;
94
- if ( emitPointerEvents ) {
95
- dispatchMouseEvent ( this . element , 'pointerup' , clientX , clientY ) ;
96
- }
86
+ this . _dispatchPointerEventIfSupported ( 'pointerup' , clientX , clientY ) ;
97
87
dispatchMouseEvent ( this . element , 'mouseup' , clientX , clientY ) ;
98
88
dispatchMouseEvent ( this . element , 'click' , clientX , clientY ) ;
99
89
@@ -115,12 +105,14 @@ export class UnitTestElement implements TestElement {
115
105
116
106
async hover ( ) : Promise < void > {
117
107
await this . _stabilize ( ) ;
108
+ this . _dispatchPointerEventIfSupported ( 'pointerenter' ) ;
118
109
dispatchMouseEvent ( this . element , 'mouseenter' ) ;
119
110
await this . _stabilize ( ) ;
120
111
}
121
112
122
113
async mouseAway ( ) : Promise < void > {
123
114
await this . _stabilize ( ) ;
115
+ this . _dispatchPointerEventIfSupported ( 'pointerleave' ) ;
124
116
dispatchMouseEvent ( this . element , 'mouseleave' ) ;
125
117
await this . _stabilize ( ) ;
126
118
}
@@ -175,4 +167,20 @@ export class UnitTestElement implements TestElement {
175
167
await this . _stabilize ( ) ;
176
168
return document . activeElement === this . element ;
177
169
}
170
+
171
+ /**
172
+ * Dispatches a pointer event on the current element if the browser supports it.
173
+ * @param name Name of the pointer event to be dispatched.
174
+ * @param clientX Coordinate of the user's pointer along the X axis.
175
+ * @param clientY Coordinate of the user's pointer along the Y axis.
176
+ */
177
+ private _dispatchPointerEventIfSupported ( name : string , clientX ?: number , clientY ?: number ) {
178
+ // The latest versions of all browsers we support have the new `PointerEvent` API.
179
+ // Though since we capture the two most recent versions of these browsers, we also
180
+ // need to support Safari 12 at time of writing. Safari 12 does not have support for this,
181
+ // so we need to conditionally create and dispatch these events based on feature detection.
182
+ if ( typeof PointerEvent !== 'undefined' && PointerEvent ) {
183
+ dispatchPointerEvent ( this . element , name , clientX , clientY ) ;
184
+ }
185
+ }
178
186
}
0 commit comments