@@ -113,4 +113,42 @@ describe('OTP', () => {
113
113
wrapper . unmount ( ) ;
114
114
} ) ;
115
115
} ) ;
116
+
117
+ it ( 'formatter' , async ( ) => {
118
+ const onChange = jest . fn ( ) ;
119
+ const wrapper = mount ( OTP , {
120
+ props : { formatter : txt => txt . toUpperCase ( ) , onChange } ,
121
+ sync : false ,
122
+ } ) ;
123
+
124
+ await asyncExpect ( async ( ) => {
125
+ const inputAll = wrapper . findAll ( 'input' ) ;
126
+ const internalValue = 'search' . split ( '' ) ;
127
+ for ( let i = 0 ; i < inputAll . length ; i ++ ) {
128
+ await inputAll [ i ] . setValue ( internalValue [ i ] ) ;
129
+ }
130
+
131
+ expect ( onChange ) . toHaveBeenCalledTimes ( 1 ) ;
132
+ expect ( onChange ) . toHaveBeenCalledWith ( 'SEARCH' ) ;
133
+
134
+ wrapper . unmount ( ) ;
135
+ } ) ;
136
+ } ) ;
137
+
138
+ it ( 'support mask prop' , async ( ) => {
139
+ const onChange = jest . fn ( ) ;
140
+ const internalValue = 'search' . split ( '' ) ;
141
+ const wrapper = mount ( OTP , { props : { mask : '🔒' , onChange } , sync : false } ) ;
142
+
143
+ await asyncExpect ( async ( ) => {
144
+ const inputAll = wrapper . findAll ( 'input' ) ;
145
+ const internalValue = 'search' . split ( '' ) ;
146
+ for ( let i = 0 ; i < inputAll . length ; i ++ ) {
147
+ await inputAll [ i ] . setValue ( internalValue [ i ] ) ;
148
+ }
149
+ expect ( onChange ) . toHaveBeenCalledTimes ( 1 ) ;
150
+ expect ( onChange ) . toHaveBeenCalledWith ( 'search' ) ;
151
+ expect ( getInputAllText ( inputAll ) ) . toBe ( '🔒🔒🔒🔒🔒🔒' ) ;
152
+ } ) ;
153
+ } ) ;
116
154
} ) ;
0 commit comments