@@ -155,13 +155,14 @@ describe('userEvent.tripleClick', () => {
155
155
} )
156
156
157
157
describe ( 'userEvent.hover, userEvent.unhover' , ( ) => {
158
- test ( 'hover works correctly' , async ( ) => {
158
+ test ( 'hover, unhover works correctly' , async ( ) => {
159
159
const target = document . createElement ( 'div' )
160
160
target . style . width = '100px'
161
161
target . style . height = '100px'
162
162
163
163
let mouseEntered = false
164
164
let pointerEntered = false
165
+
165
166
target . addEventListener ( 'mouseover' , ( ) => {
166
167
mouseEntered = true
167
168
} )
@@ -188,6 +189,46 @@ describe('userEvent.hover, userEvent.unhover', () => {
188
189
expect ( mouseEntered ) . toBe ( false )
189
190
} )
190
191
192
+ test . runIf ( server . provider === 'playwright' ) ( 'hover, unhover correctly pass options' , async ( ) => {
193
+ interface ModifiersDetected { shift : boolean ; control : boolean }
194
+ type ModifierKeys = 'Shift' | 'Control' | 'Alt' | 'ControlOrMeta' | 'Meta'
195
+
196
+ const hoverOptions = { modifiers : [ 'Shift' ] as ModifierKeys [ ] }
197
+ const unhoverOptions = { modifiers : [ 'Control' ] as ModifierKeys [ ] }
198
+
199
+ const target = document . createElement ( 'div' )
200
+ target . style . width = '100px'
201
+ target . style . height = '100px'
202
+
203
+ let modifiersDetected : ModifiersDetected = {
204
+ shift : false ,
205
+ control : false ,
206
+ }
207
+
208
+ target . addEventListener ( 'mouseover' , ( e ) => {
209
+ modifiersDetected . shift = e . shiftKey
210
+ modifiersDetected . control = e . ctrlKey
211
+ } )
212
+
213
+ target . addEventListener ( 'mouseout' , ( e ) => {
214
+ modifiersDetected . shift = e . shiftKey
215
+ modifiersDetected . control = e . ctrlKey
216
+ } )
217
+
218
+ document . body . appendChild ( target )
219
+
220
+ await userEvent . hover ( target , hoverOptions )
221
+
222
+ expect ( modifiersDetected . shift ) . toEqual ( hoverOptions . modifiers . includes ( 'Shift' ) )
223
+ expect ( modifiersDetected . control ) . toEqual ( hoverOptions . modifiers . includes ( 'Control' ) )
224
+ modifiersDetected = { shift : false , control : false }
225
+
226
+ await userEvent . unhover ( target , unhoverOptions )
227
+
228
+ expect ( modifiersDetected . shift ) . toEqual ( unhoverOptions . modifiers . includes ( 'Shift' ) )
229
+ expect ( modifiersDetected . control ) . toEqual ( unhoverOptions . modifiers . includes ( 'Control' ) )
230
+ } )
231
+
191
232
test ( 'hover works with shadow root' , async ( ) => {
192
233
const shadowRoot = createShadowRoot ( )
193
234
const target = document . createElement ( 'div' )
@@ -210,6 +251,7 @@ describe('userEvent.hover, userEvent.unhover', () => {
210
251
} )
211
252
212
253
shadowRoot . appendChild ( target )
254
+ expect . poll ( ( ) => document . body . contains ( target ) ) . toBeTruthy ( )
213
255
214
256
await userEvent . hover ( target )
215
257
0 commit comments