@@ -15,10 +15,12 @@ import {
15
15
viewRootNodes ,
16
16
TestComponentBuilder ,
17
17
RootTestComponent ,
18
- inspectElement
18
+ inspectElement ,
19
+ By
19
20
} from 'angular2/test_lib' ;
20
21
21
22
import { Injector } from 'angular2/di' ;
23
+ import { NgIf } from 'angular2/directives' ;
22
24
import { Component , View , onDestroy } from 'angular2/annotations' ;
23
25
import * as viewAnn from 'angular2/src/core/annotations_impl/view' ;
24
26
import { DynamicComponentLoader } from 'angular2/src/core/compiler/dynamic_component_loader' ;
@@ -66,6 +68,37 @@ export function main() {
66
68
} ) ;
67
69
} ) ) ;
68
70
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
+
69
102
it ( 'should update host properties' ,
70
103
inject (
71
104
[ DynamicComponentLoader , TestComponentBuilder , AsyncTestCompleter ] ,
0 commit comments