Skip to content

Commit a9c6702

Browse files
committed
fix: make everything async
1 parent 65c0126 commit a9c6702

File tree

16 files changed

+369
-331
lines changed

16 files changed

+369
-331
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
"import/prefer-default-export": "off",
5959
"import/no-unassigned-import": "off",
6060
"import/no-useless-path-segments": "off",
61-
"no-console": "off"
61+
"no-console": "off",
62+
"no-func-assign": "off"
6263
}
6364
},
6465
"eslintIgnore": [

src/user-event/.eslintrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"rules": {
3+
// the wait in the loop is intentional and we don't want to parallelize
4+
"no-await-in-loop": "off"
5+
}
6+
}

src/user-event/__tests__/clear.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as userEvent from '..'
22
import {setup} from './helpers/utils'
33

4-
test('clears text', () => {
4+
test('clears text', async () => {
55
const {element, getEventCalls} = setup('<input value="hello" />')
6-
userEvent.clear(element)
6+
await userEvent.clear(element)
77
expect(element).toHaveValue('')
88
expect(getEventCalls()).toMatchInlineSnapshot(`
99
Events fired on: input[value=""]
@@ -25,18 +25,18 @@ test('clears text', () => {
2525
`)
2626
})
2727

28-
test('does not clear text on disabled inputs', () => {
28+
test('does not clear text on disabled inputs', async () => {
2929
const {element, getEventCalls} = setup('<input value="hello" disabled />')
30-
userEvent.clear(element)
30+
await userEvent.clear(element)
3131
expect(element).toHaveValue('hello')
3232
expect(getEventCalls()).toMatchInlineSnapshot(
3333
`No events were fired on: input[value="hello"]`,
3434
)
3535
})
3636

37-
test('does not clear text on readonly inputs', () => {
37+
test('does not clear text on readonly inputs', async () => {
3838
const {element, getEventCalls} = setup('<input value="hello" readonly />')
39-
userEvent.clear(element)
39+
await userEvent.clear(element)
4040
expect(element).toHaveValue('hello')
4141
expect(getEventCalls()).toMatchInlineSnapshot(`
4242
Events fired on: input[value="hello"]
@@ -56,17 +56,17 @@ test('does not clear text on readonly inputs', () => {
5656
`)
5757
})
5858

59-
test('clears even on inputs that cannot (programmatically) have a selection', () => {
59+
test('clears even on inputs that cannot (programmatically) have a selection', async () => {
6060
const {element: email} = setup('<input value="a@b.c" type="email" />')
61-
userEvent.clear(email)
61+
await userEvent.clear(email)
6262
expect(email).toHaveValue('')
6363

6464
const {element: password} = setup('<input value="pswrd" type="password" />')
65-
userEvent.clear(password)
65+
await userEvent.clear(password)
6666
expect(password).toHaveValue('')
6767

6868
const {element: number} = setup('<input value="12" type="number" />')
69-
userEvent.clear(number)
69+
await userEvent.clear(number)
7070
// jest-dom does funny stuff with toHaveValue on number inputs
7171
expect(number.value).toBe('')
7272
})

src/user-event/__tests__/click.js

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as userEvent from '..'
22
import {setup, addEventListener, addListeners} from './helpers/utils'
33

4-
test('click in input', () => {
4+
test('click in input', async () => {
55
const {element, getEventCalls} = setup('<input />')
6-
userEvent.click(element)
6+
await userEvent.click(element)
77
expect(getEventCalls()).toMatchInlineSnapshot(`
88
Events fired on: input[value=""]
99
@@ -16,9 +16,9 @@ test('click in input', () => {
1616
`)
1717
})
1818

19-
test('click in textarea', () => {
19+
test('click in textarea', async () => {
2020
const {element, getEventCalls} = setup('<textarea></textarea>')
21-
userEvent.click(element)
21+
await userEvent.click(element)
2222
expect(getEventCalls()).toMatchInlineSnapshot(`
2323
Events fired on: textarea[value=""]
2424
@@ -31,10 +31,10 @@ test('click in textarea', () => {
3131
`)
3232
})
3333

34-
test('should fire the correct events for <input type="checkbox">', () => {
34+
test('should fire the correct events for <input type="checkbox">', async () => {
3535
const {element, getEventCalls} = setup('<input type="checkbox" />')
3636
expect(element).not.toBeChecked()
37-
userEvent.click(element)
37+
await userEvent.click(element)
3838
expect(getEventCalls()).toMatchInlineSnapshot(`
3939
Events fired on: input[checked=true]
4040
@@ -49,9 +49,9 @@ test('should fire the correct events for <input type="checkbox">', () => {
4949
`)
5050
})
5151

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 () => {
5353
const {element, getEventCalls} = setup('<input type="checkbox" disabled />')
54-
userEvent.click(element)
54+
await userEvent.click(element)
5555
expect(element).toBeDisabled()
5656
// no event calls is expected here:
5757
expect(getEventCalls()).toMatchInlineSnapshot(
@@ -61,10 +61,10 @@ test('should fire the correct events for <input type="checkbox" disabled>', () =
6161
expect(element).toHaveProperty('checked', false)
6262
})
6363

64-
test('should fire the correct events for <input type="radio">', () => {
64+
test('should fire the correct events for <input type="radio">', async () => {
6565
const {element, getEventCalls} = setup('<input type="radio" />')
6666
expect(element).not.toBeChecked()
67-
userEvent.click(element)
67+
await userEvent.click(element)
6868
expect(getEventCalls()).toMatchInlineSnapshot(`
6969
Events fired on: input[checked=true]
7070
@@ -81,9 +81,9 @@ test('should fire the correct events for <input type="radio">', () => {
8181
expect(element).toHaveProperty('checked', true)
8282
})
8383

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 () => {
8585
const {element, getEventCalls} = setup('<input type="radio" disabled />')
86-
userEvent.click(element)
86+
await userEvent.click(element)
8787
expect(element).toBeDisabled()
8888
// no event calls is expected here:
8989
expect(getEventCalls()).toMatchInlineSnapshot(
@@ -94,9 +94,9 @@ test('should fire the correct events for <input type="radio" disabled>', () => {
9494
expect(element).toHaveProperty('checked', false)
9595
})
9696

97-
test('should fire the correct events for <div>', () => {
97+
test('should fire the correct events for <div>', async () => {
9898
const {element, getEventCalls} = setup('<div></div>')
99-
userEvent.click(element)
99+
await userEvent.click(element)
100100
expect(getEventCalls()).toMatchInlineSnapshot(`
101101
Events fired on: div
102102
@@ -108,7 +108,7 @@ test('should fire the correct events for <div>', () => {
108108
`)
109109
})
110110

111-
test('toggles the focus', () => {
111+
test('toggles the focus', async () => {
112112
const {element} = setup(`<div><input /><input /></div>`)
113113

114114
const a = element.children[0]
@@ -117,26 +117,26 @@ test('toggles the focus', () => {
117117
expect(a).not.toHaveFocus()
118118
expect(b).not.toHaveFocus()
119119

120-
userEvent.click(a)
120+
await userEvent.click(a)
121121
expect(a).toHaveFocus()
122122
expect(b).not.toHaveFocus()
123123

124-
userEvent.click(b)
124+
await userEvent.click(b)
125125
expect(a).not.toHaveFocus()
126126
expect(b).toHaveFocus()
127127
})
128128

129-
test('should blur the previous element', () => {
129+
test('should blur the previous element', async () => {
130130
const {element} = setup(`<div><input /><input /></div>`)
131131

132132
const a = element.children[0]
133133
const b = element.children[1]
134134

135135
const {getEventCalls, clearEventCalls} = addListeners(a)
136136

137-
userEvent.click(a)
137+
await userEvent.click(a)
138138
clearEventCalls()
139-
userEvent.click(b)
139+
await userEvent.click(b)
140140
expect(getEventCalls()).toMatchInlineSnapshot(`
141141
Events fired on: input[value=""]
142142
@@ -146,7 +146,7 @@ test('should blur the previous element', () => {
146146
`)
147147
})
148148

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 () => {
150150
const {element} = setup(`<div><input /><input /></div>`)
151151

152152
const a = element.children[0]
@@ -156,9 +156,9 @@ test('should not blur the previous element when mousedown prevents default', ()
156156

157157
const {getEventCalls, clearEventCalls} = addListeners(a)
158158

159-
userEvent.click(a)
159+
await userEvent.click(a)
160160
clearEventCalls()
161-
userEvent.click(b)
161+
await userEvent.click(b)
162162
expect(getEventCalls()).toMatchInlineSnapshot(`
163163
Events fired on: input[value=""]
164164
@@ -167,7 +167,7 @@ test('should not blur the previous element when mousedown prevents default', ()
167167
`)
168168
})
169169

170-
test('does not lose focus when click updates focus', () => {
170+
test('does not lose focus when click updates focus', async () => {
171171
const {element} = setup(`<div><input /><button>focus</button></div>`)
172172
const input = element.children[0]
173173
const button = element.children[1]
@@ -176,14 +176,14 @@ test('does not lose focus when click updates focus', () => {
176176

177177
expect(input).not.toHaveFocus()
178178

179-
userEvent.click(button)
179+
await userEvent.click(button)
180180
expect(input).toHaveFocus()
181181

182-
userEvent.click(button)
182+
await userEvent.click(button)
183183
expect(input).toHaveFocus()
184184
})
185185

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 () => {
187187
const {element} = setup(`
188188
<div>
189189
<label for="input">label</label>
@@ -193,11 +193,11 @@ test('gives focus to the form control when clicking the label', () => {
193193
const label = element.children[0]
194194
const input = element.children[1]
195195

196-
userEvent.click(label)
196+
await userEvent.click(label)
197197
expect(input).toHaveFocus()
198198
})
199199

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 () => {
201201
const {element} = setup(`
202202
<div>
203203
<label for="input"><span>label</span></label>
@@ -208,11 +208,11 @@ test('gives focus to the form control when clicking within a label', () => {
208208
const span = label.firstChild
209209
const input = element.children[1]
210210

211-
userEvent.click(span)
211+
await userEvent.click(span)
212212
expect(input).toHaveFocus()
213213
})
214214

215-
test('clicking a label checks the checkbox', () => {
215+
test('clicking a label checks the checkbox', async () => {
216216
const {element} = setup(`
217217
<div>
218218
<label for="input">label</label>
@@ -222,12 +222,12 @@ test('clicking a label checks the checkbox', () => {
222222
const label = element.children[0]
223223
const input = element.children[1]
224224

225-
userEvent.click(label)
225+
await userEvent.click(label)
226226
expect(input).toHaveFocus()
227227
expect(input).toBeChecked()
228228
})
229229

230-
test('clicking a label checks the radio', () => {
230+
test('clicking a label checks the radio', async () => {
231231
const {element} = setup(`
232232
<div>
233233
<label for="input">label</label>
@@ -237,50 +237,50 @@ test('clicking a label checks the radio', () => {
237237
const label = element.children[0]
238238
const input = element.children[1]
239239

240-
userEvent.click(label)
240+
await userEvent.click(label)
241241
expect(input).toHaveFocus()
242242
expect(input).toBeChecked()
243243
})
244244

245-
test('submits a form when clicking on a <button>', () => {
245+
test('submits a form when clicking on a <button>', async () => {
246246
const {element, getEventCalls} = setup(`<form><button>Submit</button></form>`)
247-
userEvent.click(element.children[0])
247+
await userEvent.click(element.children[0])
248248
expect(getEventCalls()).toContain('submit')
249249
})
250250

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 () => {
252252
const {element, getEventCalls} = setup(`
253253
<form>
254254
<button type="button">Submit</button>
255255
</form>
256256
`)
257-
userEvent.click(element.children[0])
257+
await userEvent.click(element.children[0])
258258
expect(getEventCalls()).not.toContain('submit')
259259
})
260260

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 () => {
262262
const {element, getEventCalls, clearEventCalls} = setup('<button />')
263263

264-
userEvent.click(element)
264+
await userEvent.click(element)
265265
expect(getEventCalls()).not.toContain('blur')
266266

267267
clearEventCalls()
268268

269-
userEvent.click(element)
269+
await userEvent.click(element)
270270
expect(getEventCalls()).not.toContain('blur')
271271
})
272272

273-
test('does not give focus when mouseDown is prevented', () => {
273+
test('does not give focus when mouseDown is prevented', async () => {
274274
const {element} = setup('<input />', {
275275
eventHandlers: {mouseDown: e => e.preventDefault()},
276276
})
277-
userEvent.click(element)
277+
await userEvent.click(element)
278278
expect(element).not.toHaveFocus()
279279
})
280280

281-
test('fires mouse events with the correct properties', () => {
281+
test('fires mouse events with the correct properties', async () => {
282282
const {element, getEvents} = setup('<div></div>')
283-
userEvent.click(element)
283+
await userEvent.click(element)
284284
expect(getEvents()).toEqual([
285285
expect.objectContaining({
286286
type: 'mouseover',
@@ -315,9 +315,9 @@ test('fires mouse events with the correct properties', () => {
315315
])
316316
})
317317

318-
test('fires mouse events with custom button property', () => {
318+
test('fires mouse events with custom button property', async () => {
319319
const {element, getEvents} = setup('<div></div>')
320-
userEvent.click(element, {
320+
await userEvent.click(element, {
321321
button: 1,
322322
altKey: true,
323323
})
@@ -360,10 +360,10 @@ test('fires mouse events with custom button property', () => {
360360
])
361361
})
362362

363-
test('fires mouse events with custom buttons property', () => {
363+
test('fires mouse events with custom buttons property', async () => {
364364
const {element, getEvents} = setup('<div></div>')
365365

366-
userEvent.click(element, {buttons: 4})
366+
await userEvent.click(element, {buttons: 4})
367367

368368
expect(getEvents()).toEqual([
369369
expect.objectContaining({

0 commit comments

Comments
 (0)