@@ -755,6 +755,30 @@ function declareTests() {
755755 async . done ( ) ;
756756 } ) } ) ) ;
757757
758+ if ( DOM . supportsDOMEvents ( ) ) {
759+ it ( "should allow to destroy a component from within a host event handler" ,
760+ inject ( [ TestComponentBuilder ] , fakeAsync ( ( tcb : TestComponentBuilder ) => {
761+
762+ var fixture : ComponentFixture ;
763+ tcb . overrideView (
764+ MyComp , new ViewMetadata ( {
765+ template : '<push-cmp-with-host-event></push-cmp-with-host-event>' ,
766+ directives : [ [ [ PushCmpWithHostEvent ] ] ]
767+ } ) )
768+
769+ . createAsync ( MyComp )
770+ . then ( root => { fixture = root ; } ) ;
771+ tick ( ) ;
772+ fixture . detectChanges ( ) ;
773+
774+ var cmpEl = fixture . debugElement . children [ 0 ] ;
775+ var cmp : PushCmpWithHostEvent = cmpEl . inject ( PushCmpWithHostEvent ) ;
776+ cmp . ctxCallback = ( _ ) => fixture . destroy ( ) ;
777+
778+ expect ( ( ) => cmpEl . triggerEventHandler ( 'click' , < Event > { } ) ) . not . toThrow ( ) ;
779+ } ) ) ) ;
780+ }
781+
758782 it ( 'should not affect updating properties on the component' ,
759783 inject ( [ TestComponentBuilder , AsyncTestCompleter ] ,
760784 ( tcb : TestComponentBuilder , async ) => {
@@ -1995,6 +2019,16 @@ class PushCmpWithRef {
19952019 propagate ( ) { this . ref . markForCheck ( ) ; }
19962020}
19972021
2022+ @Component ( {
2023+ selector : 'push-cmp-with-host-event' ,
2024+ host : { '(click)' : 'ctxCallback($event)' } ,
2025+ changeDetection : ChangeDetectionStrategy . OnPush ,
2026+ template : ''
2027+ } )
2028+ class PushCmpWithHostEvent {
2029+ ctxCallback : Function = ( _ ) => { } ;
2030+ }
2031+
19982032@Component ( {
19992033 selector : 'push-cmp-with-async' ,
20002034 changeDetection : ChangeDetectionStrategy . OnPush ,
0 commit comments