fix(router): router should not swallow "unhandled" errors
closes #12802
This commit is contained in:
parent
768cddbe62
commit
e5a753e111
|
@ -596,7 +596,9 @@ export class Router {
|
||||||
const id = ++this.navigationId;
|
const id = ++this.navigationId;
|
||||||
this.navigations.next({id, rawUrl, prevRawUrl, extras, resolve, reject, promise});
|
this.navigations.next({id, rawUrl, prevRawUrl, extras, resolve, reject, promise});
|
||||||
|
|
||||||
return promise;
|
// Make sure that the error is propagated even though `processNavigations` catch
|
||||||
|
// handler does not rethrow
|
||||||
|
return promise.catch((e: any) => Promise.reject(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
private executeScheduledNavigation({id, rawUrl, prevRawUrl, extras, resolve,
|
private executeScheduledNavigation({id, rawUrl, prevRawUrl, extras, resolve,
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {CommonModule, Location} from '@angular/common';
|
import {CommonModule, Location} from '@angular/common';
|
||||||
import {Component, NgModule, NgModuleFactoryLoader} from '@angular/core';
|
import {Component, Injector, NgModule, NgModuleFactoryLoader} from '@angular/core';
|
||||||
import {ComponentFixture, TestBed, async, fakeAsync, inject, tick} from '@angular/core/testing';
|
import {ComponentFixture, TestBed, async, fakeAsync, inject, tick} from '@angular/core/testing';
|
||||||
import {expect} from '@angular/platform-browser/testing/matchers';
|
import {expect} from '@angular/platform-browser/testing/matchers';
|
||||||
import {Observable} from 'rxjs/Observable';
|
import {Observable} from 'rxjs/Observable';
|
||||||
|
@ -620,6 +620,19 @@ describe('Integration', () => {
|
||||||
expectEvents(recordedEvents, [[NavigationStart, '/invalid'], [NavigationError, '/invalid']]);
|
expectEvents(recordedEvents, [[NavigationStart, '/invalid'], [NavigationError, '/invalid']]);
|
||||||
})));
|
})));
|
||||||
|
|
||||||
|
it('should not swallow errors', fakeAsync(inject([Router], (router: Router) => {
|
||||||
|
const fixture = createRoot(router, RootCmp);
|
||||||
|
|
||||||
|
router.resetConfig([{path: 'simple', component: SimpleCmp}]);
|
||||||
|
|
||||||
|
router.navigateByUrl('/invalid');
|
||||||
|
expect(() => advance(fixture)).toThrow();
|
||||||
|
|
||||||
|
router.navigateByUrl('/invalid2');
|
||||||
|
expect(() => advance(fixture)).toThrow();
|
||||||
|
})));
|
||||||
|
|
||||||
|
|
||||||
it('should replace state when path is equal to current path',
|
it('should replace state when path is equal to current path',
|
||||||
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
fakeAsync(inject([Router, Location], (router: Router, location: Location) => {
|
||||||
const fixture = createRoot(router, RootCmp);
|
const fixture = createRoot(router, RootCmp);
|
||||||
|
|
Loading…
Reference in New Issue