@@ -17,7 +17,16 @@ import {specs, compile, TEST_ROUTER_PROVIDERS, clickOnElement, getHref} from '..
1717import { By } from 'angular2/platform/common_dom' ;
1818import { Router , Route , Location } from 'angular2/router' ;
1919
20- import { HelloCmp , UserCmp , TeamCmp , ParentCmp , ParentWithDefaultCmp } from './fixture_components' ;
20+ import {
21+ HelloCmp ,
22+ UserCmp ,
23+ TeamCmp ,
24+ ParentCmp ,
25+ ParentWithDefaultCmp ,
26+ DynamicLoaderCmp
27+ } from './fixture_components' ;
28+
29+ import { PromiseWrapper } from 'angular2/src/facade/async' ;
2130
2231
2332function getLinkElement ( rtc : ComponentFixture ) {
@@ -420,6 +429,55 @@ function syncRoutesWithSyncChildrenWithDefaultRoutesWithoutParams() {
420429 } ) ) ;
421430}
422431
432+ function syncRoutesWithDynamicComponents ( ) {
433+ var fixture ;
434+ var tcb ;
435+ var rtr : Router ;
436+
437+ beforeEachProviders ( ( ) => TEST_ROUTER_PROVIDERS ) ;
438+
439+ beforeEach ( inject ( [ TestComponentBuilder , Router ] , ( tcBuilder , router ) => {
440+ tcb = tcBuilder ;
441+ rtr = router ;
442+ } ) ) ;
443+
444+
445+ it ( 'should work' ,
446+ inject ( [ AsyncTestCompleter ] ,
447+ ( async ) => { tcb . createAsync ( DynamicLoaderCmp )
448+ . then ( ( rtc ) => { fixture = rtc } )
449+ . then ( ( _ ) => rtr . config ( [ new Route ( { path : '/' , component : HelloCmp } ) ] ) )
450+ . then ( ( _ ) => {
451+ fixture . detectChanges ( ) ;
452+ expect ( fixture . debugElement . nativeElement ) . toHaveText ( '{ }' ) ;
453+ return fixture . componentInstance . onSomeAction ( ) ;
454+ } )
455+ . then ( ( _ ) => {
456+ fixture . detectChanges ( ) ;
457+ return rtr . navigateByUrl ( '/' ) ;
458+ } )
459+ . then ( ( _ ) => {
460+ fixture . detectChanges ( ) ;
461+ expect ( fixture . debugElement . nativeElement ) . toHaveText ( '{ hello }' ) ;
462+
463+ return fixture . componentInstance . onSomeAction ( ) ;
464+ } )
465+ . then ( ( _ ) => {
466+
467+ // TODO(i): This should be rewritten to use NgZone#onStable or
468+ // something
469+ // similar basically the assertion needs to run when the world is
470+ // stable and we don't know when that is, only zones know.
471+ PromiseWrapper . resolve ( null ) . then ( ( _ ) => {
472+ fixture . detectChanges ( ) ;
473+ expect ( fixture . debugElement . nativeElement ) . toHaveText ( '{ hello }' ) ;
474+ async . done ( ) ;
475+ } ) ;
476+ } ) } ) ) ;
477+ }
478+
479+
480+
423481export function registerSpecs ( ) {
424482 specs [ 'syncRoutesWithoutChildrenWithoutParams' ] = syncRoutesWithoutChildrenWithoutParams ;
425483 specs [ 'syncRoutesWithoutChildrenWithParams' ] = syncRoutesWithoutChildrenWithParams ;
@@ -429,4 +487,5 @@ export function registerSpecs() {
429487 syncRoutesWithSyncChildrenWithoutDefaultRoutesWithParams ;
430488 specs [ 'syncRoutesWithSyncChildrenWithDefaultRoutesWithoutParams' ] =
431489 syncRoutesWithSyncChildrenWithDefaultRoutesWithoutParams ;
490+ specs [ 'syncRoutesWithDynamicComponents' ] = syncRoutesWithDynamicComponents ;
432491}
0 commit comments