@@ -2,9 +2,9 @@ import * as userEvent from '..'
2
2
import { setup , addEventListener , addListeners } from './helpers/utils'
3
3
4
4
test ( 'click in input' , async ( ) => {
5
- const { element, getEventCalls } = setup ( '<input />' )
5
+ const { element, getEventSnapshot } = setup ( '<input />' )
6
6
await userEvent . click ( element )
7
- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
7
+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot ( `
8
8
Events fired on: input[value=""]
9
9
10
10
input[value=""] - mouseover: Left (0)
@@ -18,9 +18,9 @@ test('click in input', async () => {
18
18
} )
19
19
20
20
test ( 'click in textarea' , async ( ) => {
21
- const { element, getEventCalls } = setup ( '<textarea></textarea>' )
21
+ const { element, getEventSnapshot } = setup ( '<textarea></textarea>' )
22
22
await userEvent . click ( element )
23
- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
23
+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot ( `
24
24
Events fired on: textarea[value=""]
25
25
26
26
textarea[value=""] - mouseover: Left (0)
@@ -34,10 +34,10 @@ test('click in textarea', async () => {
34
34
} )
35
35
36
36
test ( '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" />' )
38
38
expect ( element ) . not . toBeChecked ( )
39
39
await userEvent . click ( element )
40
- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
40
+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot ( `
41
41
Events fired on: input[checked=true]
42
42
43
43
input[checked=false] - mouseover: Left (0)
@@ -55,22 +55,24 @@ test('should fire the correct events for <input type="checkbox">', async () => {
55
55
} )
56
56
57
57
test ( '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
+ )
59
61
await userEvent . click ( element )
60
62
expect ( element ) . toBeDisabled ( )
61
63
// no event calls is expected here:
62
- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot (
64
+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot (
63
65
`No events were fired on: input[checked=false]` ,
64
66
)
65
67
expect ( element ) . toBeDisabled ( )
66
68
expect ( element ) . toHaveProperty ( 'checked' , false )
67
69
} )
68
70
69
71
test ( '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" />' )
71
73
expect ( element ) . not . toBeChecked ( )
72
74
await userEvent . click ( element )
73
- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
75
+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot ( `
74
76
Events fired on: input[checked=true]
75
77
76
78
input[checked=false] - mouseover: Left (0)
@@ -90,11 +92,11 @@ test('should fire the correct events for <input type="radio">', async () => {
90
92
} )
91
93
92
94
test ( '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 />' )
94
96
await userEvent . click ( element )
95
97
expect ( element ) . toBeDisabled ( )
96
98
// no event calls is expected here:
97
- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot (
99
+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot (
98
100
`No events were fired on: input[checked=false]` ,
99
101
)
100
102
expect ( element ) . toBeDisabled ( )
@@ -103,9 +105,9 @@ test('should fire the correct events for <input type="radio" disabled>', async (
103
105
} )
104
106
105
107
test ( 'should fire the correct events for <div>' , async ( ) => {
106
- const { element, getEventCalls } = setup ( '<div></div>' )
108
+ const { element, getEventSnapshot } = setup ( '<div></div>' )
107
109
await userEvent . click ( element )
108
- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
110
+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot ( `
109
111
Events fired on: div
110
112
111
113
div - mouseover: Left (0)
@@ -141,12 +143,12 @@ test('should blur the previous element', async () => {
141
143
const a = element . children [ 0 ]
142
144
const b = element . children [ 1 ]
143
145
144
- const { getEventCalls , clearEventCalls} = addListeners ( a )
146
+ const { getEventSnapshot , clearEventCalls} = addListeners ( a )
145
147
146
148
await userEvent . click ( a )
147
149
clearEventCalls ( )
148
150
await userEvent . click ( b )
149
- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
151
+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot ( `
150
152
Events fired on: input[name="a"][value=""]
151
153
152
154
input[name="a"][value=""] - mouseover: Left (0)
@@ -169,12 +171,12 @@ test('should not blur the previous element when mousedown prevents default', asy
169
171
170
172
addEventListener ( b , 'mousedown' , e => e . preventDefault ( ) )
171
173
172
- const { getEventCalls , clearEventCalls} = addListeners ( a )
174
+ const { getEventSnapshot , clearEventCalls} = addListeners ( a )
173
175
174
176
await userEvent . click ( a )
175
177
clearEventCalls ( )
176
178
await userEvent . click ( b )
177
- expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
179
+ expect ( getEventSnapshot ( ) ) . toMatchInlineSnapshot ( `
178
180
Events fired on: input[name="a"][value=""]
179
181
180
182
input[name="a"][value=""] - mouseover: Left (0)
@@ -268,31 +270,31 @@ test('clicking a label checks the radio', async () => {
268
270
} )
269
271
270
272
test ( '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>` )
272
274
await userEvent . click ( element . children [ 0 ] )
273
- expect ( getEventCalls ( ) ) . toContain ( 'submit' )
275
+ expect ( eventWasFired ( 'submit' ) ) . toBe ( true )
274
276
} )
275
277
276
278
test ( 'does not submit a form when clicking on a <button type="button">' , async ( ) => {
277
- const { element, getEventCalls } = setup ( `
279
+ const { element, getEventSnapshot } = setup ( `
278
280
<form>
279
281
<button type="button">Submit</button>
280
282
</form>
281
283
` )
282
284
await userEvent . click ( element . children [ 0 ] )
283
- expect ( getEventCalls ( ) ) . not . toContain ( 'submit' )
285
+ expect ( getEventSnapshot ( ) ) . not . toContain ( 'submit' )
284
286
} )
285
287
286
288
test ( '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 />' )
288
290
289
291
await userEvent . click ( element )
290
- expect ( getEventCalls ( ) ) . not . toContain ( 'blur' )
292
+ expect ( getEventSnapshot ( ) ) . not . toContain ( 'blur' )
291
293
292
294
clearEventCalls ( )
293
295
294
296
await userEvent . click ( element )
295
- expect ( getEventCalls ( ) ) . not . toContain ( 'blur' )
297
+ expect ( getEventSnapshot ( ) ) . not . toContain ( 'blur' )
296
298
} )
297
299
298
300
test ( 'does not give focus when mouseDown is prevented' , async ( ) => {
@@ -304,15 +306,9 @@ test('does not give focus when mouseDown is prevented', async () => {
304
306
} )
305
307
306
308
test ( 'fires mouse events with the correct properties' , async ( ) => {
307
- const { element, getEvents } = setup ( '<div></div>' )
309
+ const { element, getClickEventsSnapshot } = setup ( '<div></div>' )
308
310
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 ( `
316
312
mouseover - button=0; buttons=0; detail=0
317
313
mousemove - button=0; buttons=0; detail=0
318
314
mousedown - button=0; buttons=1; detail=1
@@ -323,18 +319,12 @@ test('fires mouse events with the correct properties', async () => {
323
319
} )
324
320
325
321
test ( 'fires mouse events with custom button property' , async ( ) => {
326
- const { element, getEvents } = setup ( '<div></div>' )
322
+ const { element, getClickEventsSnapshot } = setup ( '<div></div>' )
327
323
await userEvent . click ( element , {
328
324
button : 1 ,
329
325
altKey : true ,
330
326
} )
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 ( `
338
328
mouseover - button=0; buttons=0; detail=0
339
329
mousemove - button=0; buttons=0; detail=0
340
330
mousedown - button=1; buttons=4; detail=1
@@ -345,16 +335,10 @@ test('fires mouse events with custom button property', async () => {
345
335
} )
346
336
347
337
test ( 'fires mouse events with custom buttons property' , async ( ) => {
348
- const { element, getEvents } = setup ( '<div></div>' )
338
+ const { element, getClickEventsSnapshot } = setup ( '<div></div>' )
349
339
350
340
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 ( `
358
342
mouseover - button=0; buttons=0; detail=0
359
343
mousemove - button=0; buttons=0; detail=0
360
344
mousedown - button=1; buttons=4; detail=1
0 commit comments