import { async , ComponentFixture , fakeAsync , TestBed , tick } from '@angular/core/testing' ; import { HeaderComponent } from './header.component' ; import { DateTimePickerService } from '../date-time-picker.service' ; import { DateRangeService } from '../../date-range-picker/index' ; import { IconModule } from '../../icon/icon.module' ; import { ChangeDetectorRef } from '@angular/core' ; describe ( 'Date Time Picker Header' , ( ) => { let component ; let fixture ; let nativeElement ; let dateRangeService ; beforeEach ( async ( ( ) => { TestBed . configureTestingModule ( { declarations : [ HeaderComponent ] , imports : [ IconModule ] , providers : [ DateTimePickerService , DateRangeService ] } ) . compileComponents ( ) ; } ) ) ; beforeEach ( ( ) => { fixture = TestBed . createComponent ( HeaderComponent ) ; component = fixture . componentInstance ; nativeElement = fixture . nativeElement ; dateRangeService = TestBed . get ( DateRangeService ) ; fixture . detectChanges ( ) ; } ) ; it ( 'should detect changes on range change' , fakeAsync ( ( ) => { const detectChangesSpy = spyOn ( ( ( component as any ) . _changeDetector as ChangeDetectorRef ) , 'detectChanges' ) ; dateRangeService . onRangeChange . next ( ) ; tick ( 100 ) ; expect ( detectChangesSpy ) . toHaveBeenCalledTimes ( 1 ) ; } ) ) ; /** Regression test for EL-3803 - Header component called detect changes after it was destroyed throwing an error */ it ( 'should teardown correctly' , fakeAsync ( ( ) => { const detectChangesSpy = spyOn ( ( ( component as any ) . _changeDetector as ChangeDetectorRef ) , 'detectChanges' ) ; dateRangeService . onRangeChange . next ( ) ; fixture . destroy ( ) ; tick ( 100 ) ; expect ( detectChangesSpy ) . not . toHaveBeenCalled ( ) ; } ) ) ; } ) ;