@@ -60,6 +60,7 @@ describe('MatDatepicker', () => {
60
60
MultiInputDatepicker ,
61
61
NoInputDatepicker ,
62
62
StandardDatepicker ,
63
+ DatepickerWithEvents ,
63
64
] ,
64
65
} ) ;
65
66
@@ -910,6 +911,36 @@ describe('MatDatepicker', () => {
910
911
} ) ;
911
912
} ) ) ;
912
913
} ) ;
914
+
915
+ describe ( 'with events' , ( ) => {
916
+ let fixture : ComponentFixture < DatepickerWithEvents > ;
917
+ let testComponent : DatepickerWithEvents ;
918
+
919
+ beforeEach ( async ( ( ) => {
920
+ fixture = TestBed . createComponent ( DatepickerWithEvents ) ;
921
+ fixture . detectChanges ( ) ;
922
+ testComponent = fixture . componentInstance ;
923
+ } ) ) ;
924
+
925
+ it ( 'should dispatch an event when a datepicker is opened' , ( ) => {
926
+ testComponent . datepicker . open ( ) ;
927
+ fixture . detectChanges ( ) ;
928
+
929
+ expect ( testComponent . openedSpy ) . toHaveBeenCalled ( ) ;
930
+ } ) ;
931
+
932
+ it ( 'should dispatch an event when a datepicker is closed' , ( ) => {
933
+ testComponent . datepicker . open ( ) ;
934
+ fixture . detectChanges ( ) ;
935
+
936
+ testComponent . datepicker . close ( ) ;
937
+ fixture . detectChanges ( ) ;
938
+
939
+ expect ( testComponent . closedSpy ) . toHaveBeenCalled ( ) ;
940
+ } ) ;
941
+
942
+ } ) ;
943
+
913
944
} ) ;
914
945
915
946
describe ( 'with missing DateAdapter and MAT_DATE_FORMATS' , ( ) => {
@@ -1244,3 +1275,16 @@ class DatepickerWithISOStrings {
1244
1275
@ViewChild ( 'd' ) datepicker : MatDatepicker < Date > ;
1245
1276
@ViewChild ( MatDatepickerInput ) datepickerInput : MatDatepickerInput < Date > ;
1246
1277
}
1278
+
1279
+ @Component ( {
1280
+ template : `
1281
+ <input [(ngModel)]="selected" [matDatepicker]="d">
1282
+ <mat-datepicker (opened)="openedSpy()" (closed)="closedSpy()" #d></mat-datepicker>
1283
+ ` ,
1284
+ } )
1285
+ class DatepickerWithEvents {
1286
+ selected : Date | null = null ;
1287
+ openedSpy = jasmine . createSpy ( 'opened spy' ) ;
1288
+ closedSpy = jasmine . createSpy ( 'closed spy' ) ;
1289
+ @ViewChild ( 'd' ) datepicker : MatDatepicker < Date > ;
1290
+ }
0 commit comments