1
1
import * as userEvent from '..'
2
2
import { setup , addEventListener , addListeners } from './helpers/utils'
3
3
4
- test ( 'click in input' , ( ) => {
4
+ test ( 'click in input' , async ( ) => {
5
5
const { element, getEventCalls} = setup ( '<input />' )
6
- userEvent . click ( element )
6
+ await userEvent . click ( element )
7
7
expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
8
8
Events fired on: input[value=""]
9
9
@@ -16,9 +16,9 @@ test('click in input', () => {
16
16
` )
17
17
} )
18
18
19
- test ( 'click in textarea' , ( ) => {
19
+ test ( 'click in textarea' , async ( ) => {
20
20
const { element, getEventCalls} = setup ( '<textarea></textarea>' )
21
- userEvent . click ( element )
21
+ await userEvent . click ( element )
22
22
expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
23
23
Events fired on: textarea[value=""]
24
24
@@ -31,10 +31,10 @@ test('click in textarea', () => {
31
31
` )
32
32
} )
33
33
34
- test ( 'should fire the correct events for <input type="checkbox">' , ( ) => {
34
+ test ( 'should fire the correct events for <input type="checkbox">' , async ( ) => {
35
35
const { element, getEventCalls} = setup ( '<input type="checkbox" />' )
36
36
expect ( element ) . not . toBeChecked ( )
37
- userEvent . click ( element )
37
+ await userEvent . click ( element )
38
38
expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
39
39
Events fired on: input[checked=true]
40
40
@@ -49,9 +49,9 @@ test('should fire the correct events for <input type="checkbox">', () => {
49
49
` )
50
50
} )
51
51
52
- test ( 'should fire the correct events for <input type="checkbox" disabled>' , ( ) => {
52
+ test ( 'should fire the correct events for <input type="checkbox" disabled>' , async ( ) => {
53
53
const { element, getEventCalls} = setup ( '<input type="checkbox" disabled />' )
54
- userEvent . click ( element )
54
+ await userEvent . click ( element )
55
55
expect ( element ) . toBeDisabled ( )
56
56
// no event calls is expected here:
57
57
expect ( getEventCalls ( ) ) . toMatchInlineSnapshot (
@@ -61,10 +61,10 @@ test('should fire the correct events for <input type="checkbox" disabled>', () =
61
61
expect ( element ) . toHaveProperty ( 'checked' , false )
62
62
} )
63
63
64
- test ( 'should fire the correct events for <input type="radio">' , ( ) => {
64
+ test ( 'should fire the correct events for <input type="radio">' , async ( ) => {
65
65
const { element, getEventCalls} = setup ( '<input type="radio" />' )
66
66
expect ( element ) . not . toBeChecked ( )
67
- userEvent . click ( element )
67
+ await userEvent . click ( element )
68
68
expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
69
69
Events fired on: input[checked=true]
70
70
@@ -81,9 +81,9 @@ test('should fire the correct events for <input type="radio">', () => {
81
81
expect ( element ) . toHaveProperty ( 'checked' , true )
82
82
} )
83
83
84
- test ( 'should fire the correct events for <input type="radio" disabled>' , ( ) => {
84
+ test ( 'should fire the correct events for <input type="radio" disabled>' , async ( ) => {
85
85
const { element, getEventCalls} = setup ( '<input type="radio" disabled />' )
86
- userEvent . click ( element )
86
+ await userEvent . click ( element )
87
87
expect ( element ) . toBeDisabled ( )
88
88
// no event calls is expected here:
89
89
expect ( getEventCalls ( ) ) . toMatchInlineSnapshot (
@@ -94,9 +94,9 @@ test('should fire the correct events for <input type="radio" disabled>', () => {
94
94
expect ( element ) . toHaveProperty ( 'checked' , false )
95
95
} )
96
96
97
- test ( 'should fire the correct events for <div>' , ( ) => {
97
+ test ( 'should fire the correct events for <div>' , async ( ) => {
98
98
const { element, getEventCalls} = setup ( '<div></div>' )
99
- userEvent . click ( element )
99
+ await userEvent . click ( element )
100
100
expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
101
101
Events fired on: div
102
102
@@ -108,7 +108,7 @@ test('should fire the correct events for <div>', () => {
108
108
` )
109
109
} )
110
110
111
- test ( 'toggles the focus' , ( ) => {
111
+ test ( 'toggles the focus' , async ( ) => {
112
112
const { element} = setup ( `<div><input /><input /></div>` )
113
113
114
114
const a = element . children [ 0 ]
@@ -117,26 +117,26 @@ test('toggles the focus', () => {
117
117
expect ( a ) . not . toHaveFocus ( )
118
118
expect ( b ) . not . toHaveFocus ( )
119
119
120
- userEvent . click ( a )
120
+ await userEvent . click ( a )
121
121
expect ( a ) . toHaveFocus ( )
122
122
expect ( b ) . not . toHaveFocus ( )
123
123
124
- userEvent . click ( b )
124
+ await userEvent . click ( b )
125
125
expect ( a ) . not . toHaveFocus ( )
126
126
expect ( b ) . toHaveFocus ( )
127
127
} )
128
128
129
- test ( 'should blur the previous element' , ( ) => {
129
+ test ( 'should blur the previous element' , async ( ) => {
130
130
const { element} = setup ( `<div><input /><input /></div>` )
131
131
132
132
const a = element . children [ 0 ]
133
133
const b = element . children [ 1 ]
134
134
135
135
const { getEventCalls, clearEventCalls} = addListeners ( a )
136
136
137
- userEvent . click ( a )
137
+ await userEvent . click ( a )
138
138
clearEventCalls ( )
139
- userEvent . click ( b )
139
+ await userEvent . click ( b )
140
140
expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
141
141
Events fired on: input[value=""]
142
142
@@ -146,7 +146,7 @@ test('should blur the previous element', () => {
146
146
` )
147
147
} )
148
148
149
- test ( 'should not blur the previous element when mousedown prevents default' , ( ) => {
149
+ test ( 'should not blur the previous element when mousedown prevents default' , async ( ) => {
150
150
const { element} = setup ( `<div><input /><input /></div>` )
151
151
152
152
const a = element . children [ 0 ]
@@ -156,9 +156,9 @@ test('should not blur the previous element when mousedown prevents default', ()
156
156
157
157
const { getEventCalls, clearEventCalls} = addListeners ( a )
158
158
159
- userEvent . click ( a )
159
+ await userEvent . click ( a )
160
160
clearEventCalls ( )
161
- userEvent . click ( b )
161
+ await userEvent . click ( b )
162
162
expect ( getEventCalls ( ) ) . toMatchInlineSnapshot ( `
163
163
Events fired on: input[value=""]
164
164
@@ -167,7 +167,7 @@ test('should not blur the previous element when mousedown prevents default', ()
167
167
` )
168
168
} )
169
169
170
- test ( 'does not lose focus when click updates focus' , ( ) => {
170
+ test ( 'does not lose focus when click updates focus' , async ( ) => {
171
171
const { element} = setup ( `<div><input /><button>focus</button></div>` )
172
172
const input = element . children [ 0 ]
173
173
const button = element . children [ 1 ]
@@ -176,14 +176,14 @@ test('does not lose focus when click updates focus', () => {
176
176
177
177
expect ( input ) . not . toHaveFocus ( )
178
178
179
- userEvent . click ( button )
179
+ await userEvent . click ( button )
180
180
expect ( input ) . toHaveFocus ( )
181
181
182
- userEvent . click ( button )
182
+ await userEvent . click ( button )
183
183
expect ( input ) . toHaveFocus ( )
184
184
} )
185
185
186
- test ( 'gives focus to the form control when clicking the label' , ( ) => {
186
+ test ( 'gives focus to the form control when clicking the label' , async ( ) => {
187
187
const { element} = setup ( `
188
188
<div>
189
189
<label for="input">label</label>
@@ -193,11 +193,11 @@ test('gives focus to the form control when clicking the label', () => {
193
193
const label = element . children [ 0 ]
194
194
const input = element . children [ 1 ]
195
195
196
- userEvent . click ( label )
196
+ await userEvent . click ( label )
197
197
expect ( input ) . toHaveFocus ( )
198
198
} )
199
199
200
- test ( 'gives focus to the form control when clicking within a label' , ( ) => {
200
+ test ( 'gives focus to the form control when clicking within a label' , async ( ) => {
201
201
const { element} = setup ( `
202
202
<div>
203
203
<label for="input"><span>label</span></label>
@@ -208,11 +208,11 @@ test('gives focus to the form control when clicking within a label', () => {
208
208
const span = label . firstChild
209
209
const input = element . children [ 1 ]
210
210
211
- userEvent . click ( span )
211
+ await userEvent . click ( span )
212
212
expect ( input ) . toHaveFocus ( )
213
213
} )
214
214
215
- test ( 'clicking a label checks the checkbox' , ( ) => {
215
+ test ( 'clicking a label checks the checkbox' , async ( ) => {
216
216
const { element} = setup ( `
217
217
<div>
218
218
<label for="input">label</label>
@@ -222,12 +222,12 @@ test('clicking a label checks the checkbox', () => {
222
222
const label = element . children [ 0 ]
223
223
const input = element . children [ 1 ]
224
224
225
- userEvent . click ( label )
225
+ await userEvent . click ( label )
226
226
expect ( input ) . toHaveFocus ( )
227
227
expect ( input ) . toBeChecked ( )
228
228
} )
229
229
230
- test ( 'clicking a label checks the radio' , ( ) => {
230
+ test ( 'clicking a label checks the radio' , async ( ) => {
231
231
const { element} = setup ( `
232
232
<div>
233
233
<label for="input">label</label>
@@ -237,50 +237,50 @@ test('clicking a label checks the radio', () => {
237
237
const label = element . children [ 0 ]
238
238
const input = element . children [ 1 ]
239
239
240
- userEvent . click ( label )
240
+ await userEvent . click ( label )
241
241
expect ( input ) . toHaveFocus ( )
242
242
expect ( input ) . toBeChecked ( )
243
243
} )
244
244
245
- test ( 'submits a form when clicking on a <button>' , ( ) => {
245
+ test ( 'submits a form when clicking on a <button>' , async ( ) => {
246
246
const { element, getEventCalls} = setup ( `<form><button>Submit</button></form>` )
247
- userEvent . click ( element . children [ 0 ] )
247
+ await userEvent . click ( element . children [ 0 ] )
248
248
expect ( getEventCalls ( ) ) . toContain ( 'submit' )
249
249
} )
250
250
251
- test ( 'does not submit a form when clicking on a <button type="button">' , ( ) => {
251
+ test ( 'does not submit a form when clicking on a <button type="button">' , async ( ) => {
252
252
const { element, getEventCalls} = setup ( `
253
253
<form>
254
254
<button type="button">Submit</button>
255
255
</form>
256
256
` )
257
- userEvent . click ( element . children [ 0 ] )
257
+ await userEvent . click ( element . children [ 0 ] )
258
258
expect ( getEventCalls ( ) ) . not . toContain ( 'submit' )
259
259
} )
260
260
261
- test ( 'does not fire blur on current element if is the same as previous' , ( ) => {
261
+ test ( 'does not fire blur on current element if is the same as previous' , async ( ) => {
262
262
const { element, getEventCalls, clearEventCalls} = setup ( '<button />' )
263
263
264
- userEvent . click ( element )
264
+ await userEvent . click ( element )
265
265
expect ( getEventCalls ( ) ) . not . toContain ( 'blur' )
266
266
267
267
clearEventCalls ( )
268
268
269
- userEvent . click ( element )
269
+ await userEvent . click ( element )
270
270
expect ( getEventCalls ( ) ) . not . toContain ( 'blur' )
271
271
} )
272
272
273
- test ( 'does not give focus when mouseDown is prevented' , ( ) => {
273
+ test ( 'does not give focus when mouseDown is prevented' , async ( ) => {
274
274
const { element} = setup ( '<input />' , {
275
275
eventHandlers : { mouseDown : e => e . preventDefault ( ) } ,
276
276
} )
277
- userEvent . click ( element )
277
+ await userEvent . click ( element )
278
278
expect ( element ) . not . toHaveFocus ( )
279
279
} )
280
280
281
- test ( 'fires mouse events with the correct properties' , ( ) => {
281
+ test ( 'fires mouse events with the correct properties' , async ( ) => {
282
282
const { element, getEvents} = setup ( '<div></div>' )
283
- userEvent . click ( element )
283
+ await userEvent . click ( element )
284
284
expect ( getEvents ( ) ) . toEqual ( [
285
285
expect . objectContaining ( {
286
286
type : 'mouseover' ,
@@ -315,9 +315,9 @@ test('fires mouse events with the correct properties', () => {
315
315
] )
316
316
} )
317
317
318
- test ( 'fires mouse events with custom button property' , ( ) => {
318
+ test ( 'fires mouse events with custom button property' , async ( ) => {
319
319
const { element, getEvents} = setup ( '<div></div>' )
320
- userEvent . click ( element , {
320
+ await userEvent . click ( element , {
321
321
button : 1 ,
322
322
altKey : true ,
323
323
} )
@@ -360,10 +360,10 @@ test('fires mouse events with custom button property', () => {
360
360
] )
361
361
} )
362
362
363
- test ( 'fires mouse events with custom buttons property' , ( ) => {
363
+ test ( 'fires mouse events with custom buttons property' , async ( ) => {
364
364
const { element, getEvents} = setup ( '<div></div>' )
365
365
366
- userEvent . click ( element , { buttons : 4 } )
366
+ await userEvent . click ( element , { buttons : 4 } )
367
367
368
368
expect ( getEvents ( ) ) . toEqual ( [
369
369
expect . objectContaining ( {
0 commit comments