@@ -11,7 +11,7 @@ import {TestBed} from '@angular/core/testing';
1111import { expect } from '@angular/core/testing/src/testing_internal' ;
1212import { onlyInIvy } from '@angular/private/testing' ;
1313
14- import { AfterContentChecked , AfterContentInit , AfterViewChecked , AfterViewInit , Component , DoCheck , ErrorHandler , EventEmitter , Input , OnChanges , OnInit , Output , ViewChild } from '../../src/core' ;
14+ import { AfterContentChecked , AfterContentInit , AfterViewChecked , AfterViewInit , Component , DoCheck , ErrorHandler , EventEmitter , Input , OnChanges , OnDestroy , OnInit , Output , ViewChild } from '../../src/core' ;
1515
1616
1717onlyInIvy ( 'Ivy-specific functionality' ) . describe ( 'profiler' , ( ) => {
@@ -187,13 +187,19 @@ onlyInIvy('Ivy-specific functionality').describe('profiler', () => {
187187
188188 describe ( 'lifecycle hooks' , ( ) => {
189189 it ( 'should call the profiler on lifecycle execution' , ( ) => {
190- @Component ( { selector : 'my-comp' , template : '{{prop}}' } )
190+ class Service implements OnDestroy {
191+ ngOnDestroy ( ) { }
192+ }
193+ @Component ( { selector : 'my-comp' , template : '{{prop}}' , providers : [ Service ] } )
191194 class MyComponent implements OnInit , AfterViewInit , AfterViewChecked , AfterContentInit ,
192- AfterContentChecked , OnChanges , DoCheck {
195+ AfterContentChecked , OnChanges , DoCheck , OnDestroy {
193196 @Input ( ) prop = 1 ;
194197
198+ constructor ( private service : Service ) { }
199+
195200 ngOnInit ( ) { }
196201 ngDoCheck ( ) { }
202+ ngOnDestroy ( ) { }
197203 ngOnChanges ( ) { }
198204 ngAfterViewInit ( ) { }
199205 ngAfterViewChecked ( ) { }
@@ -293,6 +299,27 @@ onlyInIvy('Ivy-specific functionality').describe('profiler', () => {
293299 expect ( onChangesSpy ) . toHaveBeenCalled ( ) ;
294300 expect ( ngOnChangesStart ) . toBeTruthy ( ) ;
295301 expect ( ngOnChangesEnd ) . toBeTruthy ( ) ;
302+
303+ fixture . destroy ( ) ;
304+ const ngOnDestroyStart = findProfilerCall (
305+ ( args : any [ ] ) =>
306+ args [ 0 ] === ProfilerEvent . LifecycleHookStart && args [ 2 ] === myComp . ngOnDestroy ) ;
307+ const ngOnDestroyEnd = findProfilerCall (
308+ ( args : any [ ] ) =>
309+ args [ 0 ] === ProfilerEvent . LifecycleHookEnd && args [ 2 ] === myComp . ngOnDestroy ) ;
310+
311+ expect ( ngOnDestroyStart ) . toBeTruthy ( ) ;
312+ expect ( ngOnDestroyEnd ) . toBeTruthy ( ) ;
313+
314+ const serviceNgOnDestroyStart = findProfilerCall (
315+ ( args : any [ ] ) => args [ 0 ] === ProfilerEvent . LifecycleHookStart &&
316+ args [ 2 ] === Service . prototype . ngOnDestroy ) ;
317+ const serviceNgOnDestroyEnd = findProfilerCall (
318+ ( args : any [ ] ) => args [ 0 ] === ProfilerEvent . LifecycleHookEnd &&
319+ args [ 2 ] === Service . prototype . ngOnDestroy ) ;
320+
321+ expect ( serviceNgOnDestroyStart ) . toBeTruthy ( ) ;
322+ expect ( serviceNgOnDestroyEnd ) . toBeTruthy ( ) ;
296323 } ) ;
297324 } ) ;
298325
0 commit comments