@@ -6,13 +6,13 @@ import userEvent from "../../src";
6
6
afterEach ( cleanup ) ;
7
7
8
8
describe ( "userEvent.clear" , ( ) => {
9
- it . each ( [ "input" , "textarea" ] ) ( "should clear text in <%s>" , type => {
9
+ it . each ( [ "input" , "textarea" ] ) ( "should clear text in <%s>" , ( type ) => {
10
10
const onChange = jest . fn ( ) ;
11
11
const { getByTestId } = render (
12
12
React . createElement ( type , {
13
13
"data-testid" : "input" ,
14
14
onChange : onChange ,
15
- value : "Hello, world!"
15
+ value : "Hello, world!" ,
16
16
} )
17
17
) ;
18
18
@@ -23,15 +23,15 @@ describe("userEvent.clear", () => {
23
23
24
24
it . each ( [ "input" , "textarea" ] ) (
25
25
"should not clear when <%s> is disabled" ,
26
- type => {
26
+ ( type ) => {
27
27
const text = "Hello, world!" ;
28
28
const onChange = jest . fn ( ) ;
29
29
const { getByTestId } = render (
30
30
React . createElement ( type , {
31
31
"data-testid" : "input" ,
32
32
onChange : onChange ,
33
33
value : text ,
34
- disabled : true
34
+ disabled : true ,
35
35
} )
36
36
) ;
37
37
@@ -43,7 +43,7 @@ describe("userEvent.clear", () => {
43
43
44
44
it . each ( [ "input" , "textarea" ] ) (
45
45
"should not clear when <%s> is readOnly" ,
46
- type => {
46
+ ( type ) => {
47
47
const onChange = jest . fn ( ) ;
48
48
const onKeyDown = jest . fn ( ) ;
49
49
const onKeyUp = jest . fn ( ) ;
@@ -56,7 +56,7 @@ describe("userEvent.clear", () => {
56
56
onKeyDown,
57
57
onKeyUp,
58
58
value : text ,
59
- readOnly : true
59
+ readOnly : true ,
60
60
} )
61
61
) ;
62
62
@@ -67,4 +67,28 @@ describe("userEvent.clear", () => {
67
67
expect ( input ) . toHaveProperty ( "value" , text ) ;
68
68
}
69
69
) ;
70
+
71
+ [ "email" , "password" , "number" , "text" ] . forEach ( ( type ) => {
72
+ it . each ( [ "input" , "textarea" ] ) (
73
+ `should clear when <%s> is of type="${ type } "` ,
74
+ ( inputType ) => {
75
+ const value = "12345" ;
76
+ const placeholder = "Enter password" ;
77
+
78
+ const element = React . createElement ( inputType , {
79
+ value,
80
+ placeholder,
81
+ type,
82
+ onChange : jest . fn ( ) ,
83
+ } ) ;
84
+
85
+ const { getByPlaceholderText } = render ( element ) ;
86
+
87
+ const input = getByPlaceholderText ( placeholder ) ;
88
+ expect ( input . value ) . toBe ( value ) ;
89
+ userEvent . clear ( input ) ;
90
+ expect ( input . value ) . toBe ( "" ) ;
91
+ }
92
+ ) ;
93
+ } ) ;
70
94
} ) ;
0 commit comments