File tree Expand file tree Collapse file tree 3 files changed +7
-6
lines changed
projects/testing-library/src/lib/user-events Expand file tree Collapse file tree 3 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ export function createType(fireEvent: FireFunction & FireObject) {
3636 } ;
3737 }
3838
39- return async function type ( element : HTMLElement , value : string , options ?: TypeOptions ) {
39+ return async function type ( element : HTMLElement , value : string | number , options ?: TypeOptions ) {
4040 const { allAtOnce = false , delay = 0 } = options || { } ;
4141 const initialValue = ( element as HTMLInputElement ) . value ;
4242
@@ -46,9 +46,10 @@ export function createType(fireEvent: FireFunction & FireObject) {
4646 return ;
4747 }
4848
49+ const text = value . toString ( ) ;
4950 let actuallyTyped = '' ;
50- for ( let index = 0 ; index < value . length ; index ++ ) {
51- const char = value [ index ] ;
51+ for ( let index = 0 ; index < text . length ; index ++ ) {
52+ const char = text [ index ] ;
5253 const key = char ;
5354 const keyCode = char . charCodeAt ( 0 ) ;
5455
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ test('is possible to fill in a form and verify error messages (with the help of
2727 expect ( component . queryByText ( 'color is required' ) ) . not . toBeInTheDocument ( ) ;
2828
2929 expect ( scoreControl ) . toBeInvalid ( ) ;
30- component . type ( scoreControl , '7' ) ;
30+ component . type ( scoreControl , 7 ) ;
3131 expect ( scoreControl ) . toBeValid ( ) ;
3232
3333 expect ( errors ) . not . toBeInTheDocument ( ) ;
Original file line number Diff line number Diff line change @@ -19,15 +19,15 @@ test('is possible to fill in a form and verify error messages (with the help of
1919 expect ( errors ) . toContainElement ( component . queryByText ( 'color is required' ) ) ;
2020
2121 component . type ( nameControl , 'Tim' ) ;
22- component . type ( scoreControl , '12' ) ;
22+ component . type ( scoreControl , 12 ) ;
2323 component . selectOptions ( colorControl , 'Green' ) ;
2424
2525 expect ( component . queryByText ( 'name is required' ) ) . not . toBeInTheDocument ( ) ;
2626 expect ( component . queryByText ( 'score must be lesser than 10' ) ) . toBeInTheDocument ( ) ;
2727 expect ( component . queryByText ( 'color is required' ) ) . not . toBeInTheDocument ( ) ;
2828
2929 expect ( scoreControl ) . toBeInvalid ( ) ;
30- component . type ( scoreControl , '7' ) ;
30+ component . type ( scoreControl , 7 ) ;
3131 expect ( scoreControl ) . toBeValid ( ) ;
3232
3333 expect ( errors ) . not . toBeInTheDocument ( ) ;
You can’t perform that action at this time.
0 commit comments