@@ -60,6 +60,7 @@ describe('MatDatepicker', () => {
6060 MultiInputDatepicker ,
6161 NoInputDatepicker ,
6262 StandardDatepicker ,
63+ DatepickerWithEvents ,
6364 ] ,
6465 } ) ;
6566
@@ -906,6 +907,36 @@ describe('MatDatepicker', () => {
906907 } ) ;
907908 } ) ) ;
908909 } ) ;
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+
909940 } ) ;
910941
911942 describe ( 'with missing DateAdapter and MAT_DATE_FORMATS' , ( ) => {
@@ -1240,3 +1271,16 @@ class DatepickerWithISOStrings {
12401271 @ViewChild ( 'd' ) datepicker : MatDatepicker < Date > ;
12411272 @ViewChild ( MatDatepickerInput ) datepickerInput : MatDatepickerInput < Date > ;
12421273}
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