@@ -2,9 +2,9 @@ import * as userEvent from '..'
22import { setup , addEventListener , addListeners } from './helpers/utils'
33
44test ( 'click in input' , async ( ) => {
5- const { element, getEventCalls } = setup ( '<input />' )
5+ const { element, getEventSnapshot } = setup ( '<input />' )
66 await userEvent . click ( element )
7- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
7+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot ( `
88 Events fired on: input[value=""]
99
1010 input[value=""] - mouseover: Left (0)
@@ -18,9 +18,9 @@ test('click in input', async () => {
1818} )
1919
2020test ( 'click in textarea' , async ( ) => {
21- const { element, getEventCalls } = setup ( '<textarea></textarea>' )
21+ const { element, getEventSnapshot } = setup ( '<textarea></textarea>' )
2222 await userEvent . click ( element )
23- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
23+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot ( `
2424 Events fired on: textarea[value=""]
2525
2626 textarea[value=""] - mouseover: Left (0)
@@ -34,10 +34,10 @@ test('click in textarea', async () => {
3434} )
3535
3636test ( 'should fire the correct events for <input type="checkbox">' , async ( ) => {
37- const { element, getEventCalls } = setup ( '<input type="checkbox" />' )
37+ const { element, getEventSnapshot } = setup ( '<input type="checkbox" />' )
3838 expect ( element ) . not . toBeChecked ( )
3939 await userEvent . click ( element )
40- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
40+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot ( `
4141 Events fired on: input[checked=true]
4242
4343 input[checked=false] - mouseover: Left (0)
@@ -55,22 +55,24 @@ test('should fire the correct events for <input type="checkbox">', async () => {
5555} )
5656
5757test ( 'should fire the correct events for <input type="checkbox" disabled>' , async ( ) => {
58- const { element, getEventCalls} = setup ( '<input type="checkbox" disabled />' )
58+ const { element, getEventSnapshot} = setup (
59+ '<input type="checkbox" disabled />' ,
60+ )
5961 await userEvent . click ( element )
6062 expect ( element ) . toBeDisabled ( )
6163 // no event calls is expected here:
62- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot (
64+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot (
6365 `No events were fired on: input[checked=false]` ,
6466 )
6567 expect ( element ) . toBeDisabled ( )
6668 expect ( element ) . toHaveProperty ( 'checked' , false )
6769} )
6870
6971test ( 'should fire the correct events for <input type="radio">' , async ( ) => {
70- const { element, getEventCalls } = setup ( '<input type="radio" />' )
72+ const { element, getEventSnapshot } = setup ( '<input type="radio" />' )
7173 expect ( element ) . not . toBeChecked ( )
7274 await userEvent . click ( element )
73- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
75+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot ( `
7476 Events fired on: input[checked=true]
7577
7678 input[checked=false] - mouseover: Left (0)
@@ -90,11 +92,11 @@ test('should fire the correct events for <input type="radio">', async () => {
9092} )
9193
9294test ( 'should fire the correct events for <input type="radio" disabled>' , async ( ) => {
93- const { element, getEventCalls } = setup ( '<input type="radio" disabled />' )
95+ const { element, getEventSnapshot } = setup ( '<input type="radio" disabled />' )
9496 await userEvent . click ( element )
9597 expect ( element ) . toBeDisabled ( )
9698 // no event calls is expected here:
97- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot (
99+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot (
98100 `No events were fired on: input[checked=false]` ,
99101 )
100102 expect ( element ) . toBeDisabled ( )
@@ -103,9 +105,9 @@ test('should fire the correct events for <input type="radio" disabled>', async (
103105} )
104106
105107test ( 'should fire the correct events for <div>' , async ( ) => {
106- const { element, getEventCalls } = setup ( '<div></div>' )
108+ const { element, getEventSnapshot } = setup ( '<div></div>' )
107109 await userEvent . click ( element )
108- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
110+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot ( `
109111 Events fired on: div
110112
111113 div - mouseover: Left (0)
@@ -141,12 +143,12 @@ test('should blur the previous element', async () => {
141143 const a = element . children [ 0 ]
142144 const b = element . children [ 1 ]
143145
144- const { getEventCalls , clearEventCalls} = addListeners ( a )
146+ const { getEventSnapshot , clearEventCalls} = addListeners ( a )
145147
146148 await userEvent . click ( a )
147149 clearEventCalls ( )
148150 await userEvent . click ( b )
149- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
151+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot ( `
150152 Events fired on: input[name="a"][value=""]
151153
152154 input[name="a"][value=""] - mouseover: Left (0)
@@ -169,12 +171,12 @@ test('should not blur the previous element when mousedown prevents default', asy
169171
170172 addEventListener ( b , 'mousedown' , e => e . preventDefault ( ) )
171173
172- const { getEventCalls , clearEventCalls} = addListeners ( a )
174+ const { getEventSnapshot , clearEventCalls} = addListeners ( a )
173175
174176 await userEvent . click ( a )
175177 clearEventCalls ( )
176178 await userEvent . click ( b )
177- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
179+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot ( `
178180 Events fired on: input[name="a"][value=""]
179181
180182 input[name="a"][value=""] - mouseover: Left (0)
@@ -268,31 +270,31 @@ test('clicking a label checks the radio', async () => {
268270} )
269271
270272test ( 'submits a form when clicking on a <button>' , async ( ) => {
271- const { element, getEventCalls } = setup ( `<form><button>Submit</button></form>` )
273+ const { element, eventWasFired } = setup ( `<form><button>Submit</button></form>` )
272274 await userEvent . click ( element . children [ 0 ] )
273- expect ( getEventCalls ( ) ) . toContain ( 'submit' )
275+ expect ( eventWasFired ( 'submit' ) ) . toBe ( true )
274276} )
275277
276278test ( 'does not submit a form when clicking on a <button type="button">' , async ( ) => {
277- const { element, getEventCalls } = setup ( `
279+ const { element, getEventSnapshot } = setup ( `
278280 <form>
279281 <button type="button">Submit</button>
280282 </form>
281283 ` )
282284 await userEvent . click ( element . children [ 0 ] )
283- expect ( getEventCalls ( ) ) . not . toContain ( 'submit' )
285+ expect ( getEventSnapshot ( ) ) . not . toContain ( 'submit' )
284286} )
285287
286288test ( 'does not fire blur on current element if is the same as previous' , async ( ) => {
287- const { element, getEventCalls , clearEventCalls} = setup ( '<button />' )
289+ const { element, getEventSnapshot , clearEventCalls} = setup ( '<button />' )
288290
289291 await userEvent . click ( element )
290- expect ( getEventCalls ( ) ) . not . toContain ( 'blur' )
292+ expect ( getEventSnapshot ( ) ) . not . toContain ( 'blur' )
291293
292294 clearEventCalls ( )
293295
294296 await userEvent . click ( element )
295- expect ( getEventCalls ( ) ) . not . toContain ( 'blur' )
297+ expect ( getEventSnapshot ( ) ) . not . toContain ( 'blur' )
296298} )
297299
298300test ( 'does not give focus when mouseDown is prevented' , async ( ) => {
@@ -304,15 +306,9 @@ test('does not give focus when mouseDown is prevented', async () => {
304306} )
305307
306308test ( 'fires mouse events with the correct properties' , async ( ) => {
307- const { element, getEvents } = setup ( '<div></div>' )
309+ const { element, getClickEventsSnapshot } = setup ( '<div></div>' )
308310 await userEvent . click ( element )
309- const events = getEvents ( ) . map (
310- ( { constructor, type, button, buttons, detail} ) =>
311- constructor . name === 'MouseEvent'
312- ? `${ type } - button=${ button } ; buttons=${ buttons } ; detail=${ detail } `
313- : type ,
314- )
315- expect ( events . join ( '\n' ) ) . toMatchInlineSnapshot ( `
311+ expect ( getClickEventsSnapshot ( ) ) . toMatchInlineSnapshot ( `
316312 mouseover - button=0; buttons=0; detail=0
317313 mousemove - button=0; buttons=0; detail=0
318314 mousedown - button=0; buttons=1; detail=1
@@ -323,18 +319,12 @@ test('fires mouse events with the correct properties', async () => {
323319} )
324320
325321test ( 'fires mouse events with custom button property' , async ( ) => {
326- const { element, getEvents } = setup ( '<div></div>' )
322+ const { element, getClickEventsSnapshot } = setup ( '<div></div>' )
327323 await userEvent . click ( element , {
328324 button : 1 ,
329325 altKey : true ,
330326 } )
331- const events = getEvents ( ) . map (
332- ( { constructor, type, button, buttons, detail} ) =>
333- constructor . name === 'MouseEvent'
334- ? `${ type } - button=${ button } ; buttons=${ buttons } ; detail=${ detail } `
335- : type ,
336- )
337- expect ( events . join ( '\n' ) ) . toMatchInlineSnapshot ( `
327+ expect ( getClickEventsSnapshot ( ) ) . toMatchInlineSnapshot ( `
338328 mouseover - button=0; buttons=0; detail=0
339329 mousemove - button=0; buttons=0; detail=0
340330 mousedown - button=1; buttons=4; detail=1
@@ -345,16 +335,10 @@ test('fires mouse events with custom button property', async () => {
345335} )
346336
347337test ( 'fires mouse events with custom buttons property' , async ( ) => {
348- const { element, getEvents } = setup ( '<div></div>' )
338+ const { element, getClickEventsSnapshot } = setup ( '<div></div>' )
349339
350340 await userEvent . click ( element , { buttons : 4 } )
351- const events = getEvents ( ) . map (
352- ( { constructor, type, button, buttons, detail} ) =>
353- constructor . name === 'MouseEvent'
354- ? `${ type } - button=${ button } ; buttons=${ buttons } ; detail=${ detail } `
355- : type ,
356- )
357- expect ( events . join ( '\n' ) ) . toMatchInlineSnapshot ( `
341+ expect ( getClickEventsSnapshot ( ) ) . toMatchInlineSnapshot ( `
358342 mouseover - button=0; buttons=0; detail=0
359343 mousemove - button=0; buttons=0; detail=0
360344 mousedown - button=1; buttons=4; detail=1
0 commit comments