@@ -11,7 +11,7 @@ import {TestBed} from '@angular/core/testing';
11
11
import { expect } from '@angular/core/testing/src/testing_internal' ;
12
12
import { onlyInIvy } from '@angular/private/testing' ;
13
13
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' ;
15
15
16
16
17
17
onlyInIvy ( 'Ivy-specific functionality' ) . describe ( 'profiler' , ( ) => {
@@ -187,13 +187,19 @@ onlyInIvy('Ivy-specific functionality').describe('profiler', () => {
187
187
188
188
describe ( 'lifecycle hooks' , ( ) => {
189
189
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 ] } )
191
194
class MyComponent implements OnInit , AfterViewInit , AfterViewChecked , AfterContentInit ,
192
- AfterContentChecked , OnChanges , DoCheck {
195
+ AfterContentChecked , OnChanges , DoCheck , OnDestroy {
193
196
@Input ( ) prop = 1 ;
194
197
198
+ constructor ( private service : Service ) { }
199
+
195
200
ngOnInit ( ) { }
196
201
ngDoCheck ( ) { }
202
+ ngOnDestroy ( ) { }
197
203
ngOnChanges ( ) { }
198
204
ngAfterViewInit ( ) { }
199
205
ngAfterViewChecked ( ) { }
@@ -293,6 +299,27 @@ onlyInIvy('Ivy-specific functionality').describe('profiler', () => {
293
299
expect ( onChangesSpy ) . toHaveBeenCalled ( ) ;
294
300
expect ( ngOnChangesStart ) . toBeTruthy ( ) ;
295
301
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 ( ) ;
296
323
} ) ;
297
324
} ) ;
298
325
0 commit comments