@@ -12,6 +12,8 @@ test('is possible to fill in a form and verify error messages (with the help of
12
12
const nameControl = screen . getByLabelText ( / n a m e / i) ;
13
13
const scoreControl = screen . getByRole ( 'spinbutton' , { name : / s c o r e / i } ) ;
14
14
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
+
15
17
const errors = screen . getByRole ( 'alert' ) ;
16
18
17
19
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
33
35
userEvent . type ( scoreControl , '7' ) ;
34
36
expect ( scoreControl ) . toBeValid ( ) ;
35
37
38
+ userEvent . type ( dateControl , '08/11/2022' ) ;
39
+
36
40
expect ( errors ) . not . toBeInTheDocument ( ) ;
37
41
38
42
expect ( nameControl ) . toHaveValue ( 'Tim' ) ;
@@ -44,7 +48,10 @@ test('is possible to fill in a form and verify error messages (with the help of
44
48
name : 'Tim' ,
45
49
score : 7 ,
46
50
} ) ;
51
+
52
+ // material doesn't add these to the form
47
53
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 ) ) ;
48
55
} ) ;
49
56
50
57
test ( 'set and show pre-set form values' , async ( ) => {
@@ -56,6 +63,7 @@ test('set and show pre-set form values', async () => {
56
63
name : 'Max' ,
57
64
score : 4 ,
58
65
color : 'B' ,
66
+ date : new Date ( 2022 , 7 , 11 ) ,
59
67
} ) ;
60
68
detectChanges ( ) ;
61
69
@@ -73,4 +81,5 @@ test('set and show pre-set form values', async () => {
73
81
score : 4 ,
74
82
} ) ;
75
83
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 ) ) ;
76
85
} ) ;
0 commit comments