From 752edca81b66ee03da6fcae4ec2000abd8aa09a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Werlang?= Date: Fri, 11 Nov 2016 16:27:32 -0200 Subject: [PATCH] test(core): ngOnDestroy called before output events are detached (#9946) closes #6984 closes #5436 --- .../change_detection_integration_spec.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/modules/@angular/core/test/linker/change_detection_integration_spec.ts b/modules/@angular/core/test/linker/change_detection_integration_spec.ts index a1d9f8962c..992394cf56 100644 --- a/modules/@angular/core/test/linker/change_detection_integration_spec.ts +++ b/modules/@angular/core/test/linker/change_detection_integration_spec.ts @@ -84,6 +84,7 @@ export function main() { CompWithRef, EmitterDirective, PushComp, + OnDestroyDirective, OrderCheckDirective2, OrderCheckDirective0, OrderCheckDirective1, @@ -1040,7 +1041,16 @@ export function main() { ]); })); - it('should call ngOnDestory on pipes', fakeAsync(() => { + it('should deliver synchronous events to parent', fakeAsync(() => { + var ctx = createCompFixture('
'); + + ctx.detectChanges(false); + ctx.destroy(); + + expect(ctx.componentInstance.a).toEqual('destroyed'); + })); + + it('should call ngOnDestroy on pipes', fakeAsync(() => { var ctx = createCompFixture('{{true | pipeWithOnDestroy }}'); ctx.detectChanges(false); @@ -1442,6 +1452,13 @@ class InjectableWithLifecycle { ngOnDestroy() { this.log.add(this.name, 'ngOnDestroy'); } } +@Directive({selector: '[onDestroyDirective]'}) +class OnDestroyDirective implements OnDestroy { + @Output('destroy') emitter = new EventEmitter(false); + + ngOnDestroy() { this.emitter.emit('destroyed'); } +} + @Directive({selector: '[orderCheck0]'}) class OrderCheckDirective0 { private _name: string;