diff --git a/modules/angular2/src/router/router.ts b/modules/angular2/src/router/router.ts index 6934ba2775..a624fa3bfd 100644 --- a/modules/angular2/src/router/router.ts +++ b/modules/angular2/src/router/router.ts @@ -128,7 +128,10 @@ export class Router { ObservableWrapper.callNext(this._subject, matchedInstruction.accumulatedUrl); }); - PromiseWrapper.catchError(result, (_) => this._finishNavigating()); + PromiseWrapper.catchError(result, (err) => { + this._finishNavigating(); + return err; + }); return result; }); diff --git a/modules/angular2/test/router/router_integration_spec.ts b/modules/angular2/test/router/router_integration_spec.ts index ac69906a19..caa2842498 100644 --- a/modules/angular2/test/router/router_integration_spec.ts +++ b/modules/angular2/test/router/router_integration_spec.ts @@ -21,6 +21,8 @@ import {routerInjectables, Router} from 'angular2/router'; import {RouterOutlet} from 'angular2/src/router/router_outlet'; import {SpyLocation} from 'angular2/src/mock/location_mock'; import {Location} from 'angular2/src/router/location'; +import {PromiseWrapper} from 'angular2/src/facade/async'; +import {BaseException} from 'angular2/src/facade/lang'; export function main() { describe('router injectables', () => { @@ -47,6 +49,19 @@ export function main() { }); })); + it('should rethrow exceptions from component constructors', + inject([AsyncTestCompleter], (async) => { + bootstrap(BrokenAppCmp, testBindings) + .then((applicationRef) => { + var router = applicationRef.hostComponent.router; + PromiseWrapper.catchError(router.navigate('/cause-error'), (error) => { + expect(el).toHaveText('outer { oh no }'); + expect(error.message).toBe('oops!'); + async.done(); + }); + }); + })); + // TODO: add a test in which the child component has bindings }); } @@ -57,7 +72,6 @@ export function main() { class HelloCmp { } - @Component({selector: 'app-cmp'}) @View({template: "outer { }", directives: [RouterOutlet]}) @RouteConfig([{path: '/', component: HelloCmp}]) @@ -65,3 +79,17 @@ class AppCmp { router: Router; constructor(router: Router) { this.router = router; } } + +@Component({selector: 'oops-cmp'}) +@View({template: "oh no"}) +class BrokenCmp { + constructor() { throw new BaseException('oops!'); } +} + +@Component({selector: 'app-cmp'}) +@View({template: "outer { }", directives: [RouterOutlet]}) +@RouteConfig([{path: '/cause-error', component: BrokenCmp}]) +class BrokenAppCmp { + router: Router; + constructor(router: Router) { this.router = router; } +}