@@ -15,10 +15,12 @@ import {
1515 viewRootNodes ,
1616 TestComponentBuilder ,
1717 RootTestComponent ,
18- inspectElement
18+ inspectElement ,
19+ By
1920} from 'angular2/test_lib' ;
2021
2122import { Injector } from 'angular2/di' ;
23+ import { NgIf } from 'angular2/directives' ;
2224import { Component , View , onDestroy } from 'angular2/annotations' ;
2325import * as viewAnn from 'angular2/src/core/annotations_impl/view' ;
2426import { DynamicComponentLoader } from 'angular2/src/core/compiler/dynamic_component_loader' ;
@@ -66,6 +68,37 @@ export function main() {
6668 } ) ;
6769 } ) ) ;
6870
71+ it ( 'should allow to dispose even if the location has been removed' ,
72+ inject ( [ DynamicComponentLoader , TestComponentBuilder , AsyncTestCompleter ] ,
73+ ( loader , tcb : TestComponentBuilder , async ) => {
74+ tcb . overrideView ( MyComp , new viewAnn . View ( {
75+ template : '<child-cmp *ng-if="ctxBoolProp"></child-cmp>' ,
76+ directives : [ NgIf , ChildComp ]
77+ } ) )
78+ . overrideView (
79+ ChildComp ,
80+ new viewAnn . View (
81+ { template : '<location #loc></location>' , directives : [ Location ] } ) )
82+ . createAsync ( MyComp )
83+ . then ( ( tc ) => {
84+ tc . componentInstance . ctxBoolProp = true ;
85+ tc . detectChanges ( ) ;
86+ var childCompEl = tc . query ( By . css ( 'child-cmp' ) ) ;
87+ loader . loadIntoLocation ( DynamicallyLoaded , childCompEl . elementRef , 'loc' )
88+ . then ( ref => {
89+ expect ( tc . nativeElement ) . toHaveText ( "Location;DynamicallyLoaded;" ) ;
90+
91+ tc . componentInstance . ctxBoolProp = false ;
92+ tc . detectChanges ( ) ;
93+ expect ( tc . nativeElement ) . toHaveText ( "" ) ;
94+
95+ ref . dispose ( ) ;
96+ expect ( tc . nativeElement ) . toHaveText ( "" ) ;
97+ async . done ( ) ;
98+ } ) ;
99+ } ) ;
100+ } ) ) ;
101+
69102 it ( 'should update host properties' ,
70103 inject (
71104 [ DynamicComponentLoader , TestComponentBuilder , AsyncTestCompleter ] ,
0 commit comments