@@ -155,13 +155,14 @@ describe('userEvent.tripleClick', () => {
155155} )
156156
157157describe ( 'userEvent.hover, userEvent.unhover' , ( ) => {
158- test ( 'hover works correctly' , async ( ) => {
158+ test ( 'hover, unhover works correctly' , async ( ) => {
159159 const target = document . createElement ( 'div' )
160160 target . style . width = '100px'
161161 target . style . height = '100px'
162162
163163 let mouseEntered = false
164164 let pointerEntered = false
165+
165166 target . addEventListener ( 'mouseover' , ( ) => {
166167 mouseEntered = true
167168 } )
@@ -188,6 +189,46 @@ describe('userEvent.hover, userEvent.unhover', () => {
188189 expect ( mouseEntered ) . toBe ( false )
189190 } )
190191
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+
191232 test ( 'hover works with shadow root' , async ( ) => {
192233 const shadowRoot = createShadowRoot ( )
193234 const target = document . createElement ( 'div' )
@@ -210,6 +251,7 @@ describe('userEvent.hover, userEvent.unhover', () => {
210251 } )
211252
212253 shadowRoot . appendChild ( target )
254+ expect . poll ( ( ) => document . body . contains ( target ) ) . toBeTruthy ( )
213255
214256 await userEvent . hover ( target )
215257
0 commit comments