@@ -2,7 +2,7 @@ import React from 'react'
2
2
import { render , screen } from '@testing-library/react'
3
3
import userEvent from '../../src'
4
4
5
- test . each ( [ 'input' , 'textarea' ] ) ( 'should type text in <%s>' , type => {
5
+ test . each ( [ 'input' , 'textarea' ] ) ( 'should type text in <%s>' , async type => {
6
6
const onChange = jest . fn ( )
7
7
render (
8
8
React . createElement ( type , {
@@ -11,30 +11,30 @@ test.each(['input', 'textarea'])('should type text in <%s>', type => {
11
11
} ) ,
12
12
)
13
13
const text = 'Hello, world!'
14
- userEvent . type ( screen . getByTestId ( 'input' ) , text )
14
+ await userEvent . type ( screen . getByTestId ( 'input' ) , text )
15
15
expect ( onChange ) . toHaveBeenCalledTimes ( text . length )
16
16
expect ( screen . getByTestId ( 'input' ) ) . toHaveProperty ( 'value' , text )
17
17
} )
18
18
19
- test ( 'should append text one by one' , ( ) => {
19
+ test ( 'should append text one by one' , async ( ) => {
20
20
const onChange = jest . fn ( )
21
21
render ( < input data-testid = "input" onChange = { onChange } /> )
22
- userEvent . type ( screen . getByTestId ( 'input' ) , 'hello' )
23
- userEvent . type ( screen . getByTestId ( 'input' ) , ' world' )
22
+ await userEvent . type ( screen . getByTestId ( 'input' ) , 'hello' )
23
+ await userEvent . type ( screen . getByTestId ( 'input' ) , ' world' )
24
24
expect ( onChange ) . toHaveBeenCalledTimes ( 'hello world' . length )
25
25
expect ( screen . getByTestId ( 'input' ) ) . toHaveProperty ( 'value' , 'hello world' )
26
26
} )
27
27
28
- test ( 'should append text all at once' , ( ) => {
28
+ test ( 'should append text all at once' , async ( ) => {
29
29
const onChange = jest . fn ( )
30
30
render ( < input data-testid = "input" onChange = { onChange } /> )
31
- userEvent . type ( screen . getByTestId ( 'input' ) , 'hello' , { allAtOnce : true } )
32
- userEvent . type ( screen . getByTestId ( 'input' ) , ' world' , { allAtOnce : true } )
31
+ await userEvent . type ( screen . getByTestId ( 'input' ) , 'hello' , { allAtOnce : true } )
32
+ await userEvent . type ( screen . getByTestId ( 'input' ) , ' world' , { allAtOnce : true } )
33
33
expect ( onChange ) . toHaveBeenCalledTimes ( 2 )
34
34
expect ( screen . getByTestId ( 'input' ) ) . toHaveProperty ( 'value' , 'hello world' )
35
35
} )
36
36
37
- test ( 'should not type when event.preventDefault() is called' , ( ) => {
37
+ test ( 'should not type when event.preventDefault() is called' , async ( ) => {
38
38
const onChange = jest . fn ( )
39
39
const onKeydown = jest
40
40
. fn ( )
@@ -43,15 +43,15 @@ test('should not type when event.preventDefault() is called', () => {
43
43
< input data-testid = "input" onKeyDown = { onKeydown } onChange = { onChange } /> ,
44
44
)
45
45
const text = 'Hello, world!'
46
- userEvent . type ( screen . getByTestId ( 'input' ) , text )
46
+ await userEvent . type ( screen . getByTestId ( 'input' ) , text )
47
47
expect ( onKeydown ) . toHaveBeenCalledTimes ( text . length )
48
48
expect ( onChange ) . toHaveBeenCalledTimes ( 0 )
49
49
expect ( screen . getByTestId ( 'input' ) ) . not . toHaveProperty ( 'value' , text )
50
50
} )
51
51
52
52
test . each ( [ 'input' , 'textarea' ] ) (
53
53
'should not type when <%s> is disabled' ,
54
- type => {
54
+ async type => {
55
55
const onChange = jest . fn ( )
56
56
render (
57
57
React . createElement ( type , {
@@ -61,15 +61,15 @@ test.each(['input', 'textarea'])(
61
61
} ) ,
62
62
)
63
63
const text = 'Hello, world!'
64
- userEvent . type ( screen . getByTestId ( 'input' ) , text )
64
+ await userEvent . type ( screen . getByTestId ( 'input' ) , text )
65
65
expect ( onChange ) . not . toHaveBeenCalled ( )
66
66
expect ( screen . getByTestId ( 'input' ) ) . toHaveProperty ( 'value' , '' )
67
67
} ,
68
68
)
69
69
70
70
test . each ( [ 'input' , 'textarea' ] ) (
71
71
'should not type when <%s> is readOnly' ,
72
- type => {
72
+ async type => {
73
73
const onChange = jest . fn ( )
74
74
const onKeyDown = jest . fn ( )
75
75
const onKeyPress = jest . fn ( )
@@ -85,7 +85,7 @@ test.each(['input', 'textarea'])(
85
85
} ) ,
86
86
)
87
87
const text = 'Hello, world!'
88
- userEvent . type ( screen . getByTestId ( 'input' ) , text )
88
+ await userEvent . type ( screen . getByTestId ( 'input' ) , text )
89
89
expect ( onKeyDown ) . toHaveBeenCalledTimes ( text . length )
90
90
expect ( onKeyPress ) . toHaveBeenCalledTimes ( text . length )
91
91
expect ( onKeyUp ) . toHaveBeenCalledTimes ( text . length )
@@ -154,7 +154,7 @@ test.each(['input', 'textarea'])(
154
154
155
155
test . each ( [ 'input' , 'textarea' ] ) (
156
156
'should enter text in <%s> up to maxLength if provided' ,
157
- type => {
157
+ async type => {
158
158
const onChange = jest . fn ( )
159
159
const onKeyDown = jest . fn ( )
160
160
const onKeyPress = jest . fn ( )
@@ -177,7 +177,7 @@ test.each(['input', 'textarea'])(
177
177
178
178
const inputEl = screen . getByTestId ( 'input' )
179
179
180
- userEvent . type ( inputEl , text )
180
+ await userEvent . type ( inputEl , text )
181
181
182
182
expect ( inputEl ) . toHaveProperty ( 'value' , slicedText )
183
183
expect ( onChange ) . toHaveBeenCalledTimes ( slicedText . length )
@@ -205,7 +205,7 @@ test.each(['input', 'textarea'])(
205
205
206
206
test . each ( [ 'input' , 'textarea' ] ) (
207
207
'should append text in <%s> up to maxLength if provided' ,
208
- type => {
208
+ async type => {
209
209
const onChange = jest . fn ( )
210
210
const onKeyDown = jest . fn ( )
211
211
const onKeyPress = jest . fn ( )
@@ -230,8 +230,8 @@ test.each(['input', 'textarea'])(
230
230
231
231
const inputEl = screen . getByTestId ( 'input' )
232
232
233
- userEvent . type ( inputEl , text1 )
234
- userEvent . type ( inputEl , text2 )
233
+ await userEvent . type ( inputEl , text1 )
234
+ await userEvent . type ( inputEl , text2 )
235
235
236
236
expect ( inputEl ) . toHaveProperty ( 'value' , slicedText )
237
237
expect ( onChange ) . toHaveBeenCalledTimes ( slicedText . length )
0 commit comments