@@ -21,6 +21,8 @@ import {routerInjectables, Router} from 'angular2/router';
2121import { RouterOutlet } from 'angular2/src/router/router_outlet' ;
2222import { SpyLocation } from 'angular2/src/mock/location_mock' ;
2323import { Location } from 'angular2/src/router/location' ;
24+ import { PromiseWrapper } from 'angular2/src/facade/async' ;
25+ import { BaseException } from 'angular2/src/facade/lang' ;
2426
2527export function main ( ) {
2628 describe ( 'router injectables' , ( ) => {
@@ -47,6 +49,19 @@ export function main() {
4749 } ) ;
4850 } ) ) ;
4951
52+ it ( 'should rethrow exceptions from component constructors' ,
53+ inject ( [ AsyncTestCompleter ] , ( async ) => {
54+ bootstrap ( BrokenAppCmp , testBindings )
55+ . then ( ( applicationRef ) => {
56+ var router = applicationRef . hostComponent . router ;
57+ PromiseWrapper . catchError ( router . navigate ( '/cause-error' ) , ( error ) => {
58+ expect ( el ) . toHaveText ( 'outer { oh no }' ) ;
59+ expect ( error . message ) . toBe ( 'oops!' ) ;
60+ async . done ( ) ;
61+ } ) ;
62+ } ) ;
63+ } ) ) ;
64+
5065 // TODO: add a test in which the child component has bindings
5166 } ) ;
5267}
@@ -57,11 +72,24 @@ export function main() {
5772class HelloCmp {
5873}
5974
60-
6175@Component ( { selector : 'app-cmp' } )
6276@View ( { template : "outer { <router-outlet></router-outlet> }" , directives : [ RouterOutlet ] } )
6377@RouteConfig ( [ { path : '/' , component : HelloCmp } ] )
6478class AppCmp {
6579 router : Router ;
6680 constructor ( router : Router ) { this . router = router ; }
6781}
82+
83+ @Component ( { selector : 'oops-cmp' } )
84+ @View ( { template : "oh no" } )
85+ class BrokenCmp {
86+ constructor ( ) { throw new BaseException ( 'oops!' ) ; }
87+ }
88+
89+ @Component ( { selector : 'app-cmp' } )
90+ @View ( { template : "outer { <router-outlet></router-outlet> }" , directives : [ RouterOutlet ] } )
91+ @RouteConfig ( [ { path : '/cause-error' , component : BrokenCmp } ] )
92+ class BrokenAppCmp {
93+ router : Router ;
94+ constructor ( router : Router ) { this . router = router ; }
95+ }
0 commit comments