@@ -12,6 +12,8 @@ test('is possible to fill in a form and verify error messages (with the help of
1212 const nameControl = screen . getByLabelText ( / n a m e / i) ;
1313 const scoreControl = screen . getByRole ( 'spinbutton' , { name : / s c o r e / i } ) ;
1414 const colorControl = screen . getByRole ( 'combobox' , { name : / c o l o r / i } ) ;
15+ const dateControl = screen . getByRole ( 'textbox' , { name : / C h o o s e a d a t e / i } ) ;
16+
1517 const errors = screen . getByRole ( 'alert' ) ;
1618
1719 expect ( errors ) . toContainElement ( screen . queryByText ( 'name is required' ) ) ;
@@ -33,6 +35,8 @@ test('is possible to fill in a form and verify error messages (with the help of
3335 userEvent . type ( scoreControl , '7' ) ;
3436 expect ( scoreControl ) . toBeValid ( ) ;
3537
38+ userEvent . type ( dateControl , '08/11/2022' ) ;
39+
3640 expect ( errors ) . not . toBeInTheDocument ( ) ;
3741
3842 expect ( nameControl ) . toHaveValue ( 'Tim' ) ;
@@ -44,7 +48,10 @@ test('is possible to fill in a form and verify error messages (with the help of
4448 name : 'Tim' ,
4549 score : 7 ,
4650 } ) ;
51+
52+ // material doesn't add these to the form
4753 expect ( ( fixture . componentInstance as MaterialFormsComponent ) . form ?. get ( 'color' ) ?. value ) . toBe ( 'G' ) ;
54+ expect ( ( fixture . componentInstance as MaterialFormsComponent ) . form ?. get ( 'date' ) ?. value ) . toEqual ( new Date ( 2022 , 7 , 11 ) ) ;
4855} ) ;
4956
5057test ( 'set and show pre-set form values' , async ( ) => {
@@ -56,6 +63,7 @@ test('set and show pre-set form values', async () => {
5663 name : 'Max' ,
5764 score : 4 ,
5865 color : 'B' ,
66+ date : new Date ( 2022 , 7 , 11 ) ,
5967 } ) ;
6068 detectChanges ( ) ;
6169
@@ -73,4 +81,5 @@ test('set and show pre-set form values', async () => {
7381 score : 4 ,
7482 } ) ;
7583 expect ( ( fixture . componentInstance as MaterialFormsComponent ) . form ?. get ( 'color' ) ?. value ) . toBe ( 'B' ) ;
84+ expect ( ( fixture . componentInstance as MaterialFormsComponent ) . form ?. get ( 'date' ) ?. value ) . toEqual ( new Date ( 2022 , 7 , 11 ) ) ;
7685} ) ;
0 commit comments