@@ -1156,6 +1156,75 @@ describe('MatTimepicker', () => {
1156
1156
expect ( input . disabled ) . toBe ( true ) ;
1157
1157
expect ( fixture . componentInstance . input . disabled ( ) ) . toBe ( true ) ;
1158
1158
} ) ;
1159
+
1160
+ it ( 'should emit to valueChange before assigning control value when typing' , ( ) => {
1161
+ const fixture = TestBed . createComponent ( TimepickerWithForms ) ;
1162
+ const control = fixture . componentInstance . control ;
1163
+ let eventValue : Date | null = null ;
1164
+ let controlValue : Date | null = null ;
1165
+ fixture . detectChanges ( ) ;
1166
+
1167
+ const subscription = fixture . componentInstance . input . value . subscribe ( value => {
1168
+ eventValue = value ;
1169
+ controlValue = control . value ;
1170
+ } ) ;
1171
+
1172
+ typeInElement ( getInput ( fixture ) , '1:37 PM' ) ;
1173
+ fixture . detectChanges ( ) ;
1174
+
1175
+ expect ( eventValue ) . toBeTruthy ( ) ;
1176
+ expect ( controlValue ) . toBeTruthy ( ) ;
1177
+ expectSameTime ( eventValue , controlValue ) ;
1178
+ subscription . unsubscribe ( ) ;
1179
+ } ) ;
1180
+
1181
+ it ( 'should emit to valueChange before assigning control value when clicking an option' , ( ) => {
1182
+ const fixture = TestBed . createComponent ( TimepickerWithForms ) ;
1183
+ const control = fixture . componentInstance . control ;
1184
+ let eventValue : Date | null = null ;
1185
+ let controlValue : Date | null = null ;
1186
+ fixture . detectChanges ( ) ;
1187
+
1188
+ const subscription = fixture . componentInstance . input . value . subscribe ( value => {
1189
+ eventValue = value ;
1190
+ controlValue = control . value ;
1191
+ } ) ;
1192
+
1193
+ getInput ( fixture ) . click ( ) ;
1194
+ fixture . detectChanges ( ) ;
1195
+ getOptions ( ) [ 5 ] . click ( ) ;
1196
+ fixture . detectChanges ( ) ;
1197
+ fixture . detectChanges ( ) ;
1198
+
1199
+ expect ( eventValue ) . toBeTruthy ( ) ;
1200
+ expect ( controlValue ) . toBeTruthy ( ) ;
1201
+ expectSameTime ( eventValue , controlValue ) ;
1202
+ subscription . unsubscribe ( ) ;
1203
+ } ) ;
1204
+
1205
+ it ( 'should emit to selected event before assigning control value when clicking an option' , ( ) => {
1206
+ const fixture = TestBed . createComponent ( TimepickerWithForms ) ;
1207
+ const control = fixture . componentInstance . control ;
1208
+ let eventValue : Date | null = null ;
1209
+ let controlValue : Date | null = null ;
1210
+ fixture . detectChanges ( ) ;
1211
+
1212
+ const subscription = fixture . componentInstance . timepicker . selected . subscribe ( event => {
1213
+ eventValue = event . value ;
1214
+ controlValue = control . value ;
1215
+ } ) ;
1216
+
1217
+ getInput ( fixture ) . click ( ) ;
1218
+ fixture . detectChanges ( ) ;
1219
+ getOptions ( ) [ 5 ] . click ( ) ;
1220
+ fixture . detectChanges ( ) ;
1221
+ fixture . detectChanges ( ) ;
1222
+
1223
+ expect ( eventValue ) . toBeTruthy ( ) ;
1224
+ expect ( controlValue ) . toBeTruthy ( ) ;
1225
+ expectSameTime ( eventValue , controlValue ) ;
1226
+ subscription . unsubscribe ( ) ;
1227
+ } ) ;
1159
1228
} ) ;
1160
1229
1161
1230
describe ( 'timepicker toggle' , ( ) => {
@@ -1410,6 +1479,7 @@ class TimepickerTwoWayBinding {
1410
1479
} )
1411
1480
class TimepickerWithForms {
1412
1481
@ViewChild ( MatTimepickerInput ) input : MatTimepickerInput < Date > ;
1482
+ @ViewChild ( MatTimepicker ) timepicker : MatTimepicker < Date > ;
1413
1483
readonly control = new FormControl < Date | null > ( null , [ Validators . required ] ) ;
1414
1484
readonly min = signal < Date | null > ( null ) ;
1415
1485
readonly max = signal < Date | null > ( null ) ;
0 commit comments