@@ -35,6 +35,7 @@ import {RouteRegistry} from 'angular2/src/router/route_registry';
3535import { DirectiveResolver } from 'angular2/src/core/compiler/directive_resolver' ;
3636
3737var cmpInstanceCount ;
38+ var childCmpInstanceCount ;
3839var log : string [ ] ;
3940
4041export function main ( ) {
@@ -57,6 +58,7 @@ export function main() {
5758 beforeEach ( inject ( [ TestComponentBuilder , Router ] , ( tcBuilder , router ) => {
5859 tcb = tcBuilder ;
5960 rtr = router ;
61+ childCmpInstanceCount = 0 ;
6062 cmpInstanceCount = 0 ;
6163 log = [ ] ;
6264 } ) ) ;
@@ -147,6 +149,27 @@ export function main() {
147149 } ) ;
148150 } ) ) ;
149151
152+ it ( 'should not reuse children when parent components change' ,
153+ inject ( [ AsyncTestCompleter ] , ( async ) => {
154+ compile ( )
155+ . then ( ( _ ) => rtr . config ( [ new Route ( { path : '/team/:id/...' , component : TeamCmp } ) ] ) )
156+ . then ( ( _ ) => rtr . navigate ( '/team/angular/user/rado' ) )
157+ . then ( ( _ ) => {
158+ rootTC . detectChanges ( ) ;
159+ expect ( cmpInstanceCount ) . toBe ( 1 ) ;
160+ expect ( childCmpInstanceCount ) . toBe ( 1 ) ;
161+ expect ( rootTC . nativeElement ) . toHaveText ( 'team angular { hello rado }' ) ;
162+ } )
163+ . then ( ( _ ) => rtr . navigate ( '/team/dart/user/rado' ) )
164+ . then ( ( _ ) => {
165+ rootTC . detectChanges ( ) ;
166+ expect ( cmpInstanceCount ) . toBe ( 2 ) ;
167+ expect ( childCmpInstanceCount ) . toBe ( 2 ) ;
168+ expect ( rootTC . nativeElement ) . toHaveText ( 'team dart { hello rado }' ) ;
169+ async . done ( ) ;
170+ } ) ;
171+ } ) ) ;
172+
150173 it ( 'should inject route data into component' , inject ( [ AsyncTestCompleter ] , ( async ) => {
151174 compile ( )
152175 . then ( ( _ ) => rtr . config ( [
@@ -256,7 +279,10 @@ class RouteDataCmp {
256279@View ( { template : "hello {{user}}" } )
257280class UserCmp {
258281 user : string ;
259- constructor ( params : RouteParams ) { this . user = params . get ( 'name' ) ; }
282+ constructor ( params : RouteParams ) {
283+ childCmpInstanceCount += 1 ;
284+ this . user = params . get ( 'name' ) ;
285+ }
260286}
261287
262288
0 commit comments