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