Revert "fix(router): Update types for TypeScript nullability support"

This reverts commit 56c46d70f7.

Broke in G3.
This commit is contained in:
Tobias Bosch
2017-04-17 09:47:59 -07:00
parent 6d930d2fc5
commit ea8ffc9841
26 changed files with 223 additions and 230 deletions

View File

@ -51,7 +51,7 @@ describe('applyRedirects', () => {
});
it('should throw when cannot handle a positional parameter', () => {
applyRedirects(testModule.injector, null !, serializer, tree('/a/1'), [
applyRedirects(testModule.injector, null, serializer, tree('/a/1'), [
{path: 'a/:id', redirectTo: 'a/:other'}
]).subscribe(() => {}, (e) => {
expect(e.message).toEqual('Cannot redirect to \'a/:other\'. Cannot find \':other\'.');
@ -403,7 +403,7 @@ describe('applyRedirects', () => {
{path: '', redirectTo: 'a', pathMatch: 'full'}
];
applyRedirects(testModule.injector, null !, serializer, tree('b'), config)
applyRedirects(testModule.injector, null, serializer, tree('b'), config)
.subscribe(
(_) => { throw 'Should not be reached'; },
e => { expect(e.message).toEqual('Cannot match any routes. URL Segment: \'b\''); });
@ -533,7 +533,7 @@ describe('applyRedirects', () => {
]
}];
applyRedirects(testModule.injector, null !, serializer, tree('a/(d//aux:e)'), config)
applyRedirects(testModule.injector, null, serializer, tree('a/(d//aux:e)'), config)
.subscribe(
(_) => { throw 'Should not be reached'; },
e => { expect(e.message).toEqual('Cannot match any routes. URL Segment: \'a\''); });
@ -564,7 +564,7 @@ describe('applyRedirects', () => {
it('should error when no children matching and some url is left', () => {
applyRedirects(
testModule.injector, null !, serializer, tree('/a/c'),
testModule.injector, null, serializer, tree('/a/c'),
[{path: 'a', component: ComponentA, children: [{path: 'b', component: ComponentB}]}])
.subscribe(
(_) => { throw 'Should not be reached'; },
@ -587,7 +587,7 @@ describe('applyRedirects', () => {
matcher: matcher,
component: ComponentA,
children: [{path: 'b', component: ComponentB}]
}] as any,
}],
'/a/1/b', (t: UrlTree) => { compareTrees(t, tree('a/1/b')); });
});
});
@ -614,7 +614,7 @@ describe('applyRedirects', () => {
it('should throw when using non-absolute redirects', () => {
applyRedirects(
testModule.injector, null !, serializer, tree('a'),
testModule.injector, null, serializer, tree('a'),
[
{path: 'a', redirectTo: 'b(aux:c)'},
])
@ -629,7 +629,7 @@ describe('applyRedirects', () => {
});
function checkRedirect(config: Routes, url: string, callback: any): void {
applyRedirects(TestBed, null !, new DefaultUrlSerializer(), tree(url), config)
applyRedirects(TestBed, null, new DefaultUrlSerializer(), tree(url), config)
.subscribe(callback, e => { throw e; });
}

View File

@ -16,7 +16,7 @@ import {NavigationEnd, Resolve, Router, RouterModule} from '@angular/router';
describe('bootstrap', () => {
let log: any[] = [];
let testProviders: any[] = null !;
let testProviders: any[] = null;
@Component({selector: 'test-app', template: 'root <router-outlet></router-outlet>'})
class RootCmp {
@ -80,7 +80,7 @@ describe('bootstrap', () => {
platformBrowserDynamic([]).bootstrapModule(TestModule).then(res => {
const router = res.injector.get(Router);
const data = router.routerState.snapshot.root.firstChild !.data;
const data = router.routerState.snapshot.root.firstChild.data;
expect(data['test']).toEqual('test-data');
expect(log).toEqual(
['TestModule', 'NavigationStart', 'RoutesRecognized', 'RootCmp', 'NavigationEnd']);

View File

@ -24,8 +24,7 @@ describe('config', () => {
it('should throw for undefined route', () => {
expect(() => {
validateConfig(
[{path: 'a', component: ComponentA}, , {path: 'b', component: ComponentB}] as any);
validateConfig([{path: 'a', component: ComponentA}, , {path: 'b', component: ComponentB}]);
}).toThrowError(/Invalid configuration of route ''/);
});
@ -37,7 +36,7 @@ describe('config', () => {
{path: 'b', component: ComponentB},
,
]
}] as any);
}]);
}).toThrowError(/Invalid configuration of route 'a'/);
});
@ -99,7 +98,7 @@ describe('config', () => {
});
it('should throw when path and matcher are missing', () => {
expect(() => { validateConfig([{component: null, redirectTo: 'b'}] as any); })
expect(() => { validateConfig([{component: null, redirectTo: 'b'}]); })
.toThrowError(
`Invalid configuration of route '': routes must have either a path or a matcher specified`);
});

View File

@ -19,7 +19,7 @@ describe('create router state', () => {
const reuseStrategy = new DefaultRouteReuseStrategy();
const emptyState = () =>
createEmptyState(new UrlTree(new UrlSegmentGroup([], {}), {}, null !), RootComponent);
createEmptyState(new UrlTree(new UrlSegmentGroup([], {}), {}, null), RootComponent);
it('should work create new state', () => {
const state = createRouterState(
@ -76,8 +76,8 @@ describe('create router state', () => {
createRouterState(reuseStrategy, createState(config, 'a/2;p=22/(b//right:c)'), prevState);
expect(prevState.root).toBe(state.root);
const prevP = prevState.firstChild(prevState.root) !;
const currP = state.firstChild(state.root) !;
const prevP = prevState.firstChild(prevState.root);
const currP = state.firstChild(state.root);
expect(prevP).toBe(currP);
const prevC = prevState.children(prevP);
@ -101,7 +101,7 @@ function advanceNode(node: TreeNode<ActivatedRoute>): void {
}
function createState(config: Routes, url: string): RouterStateSnapshot {
let res: RouterStateSnapshot = undefined !;
let res: RouterStateSnapshot;
recognize(RootComponent, config, tree(url), url).forEach(s => res = s);
return res;
}

View File

@ -247,10 +247,10 @@ function createRoot(tree: UrlTree, commands: any[], queryParams?: Params, fragme
[], <any>{}, <any>{}, '', <any>{}, PRIMARY_OUTLET, 'someComponent', null, tree.root, -1,
<any>null);
const a = new ActivatedRoute(
new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !),
new BehaviorSubject(null !), new BehaviorSubject(null !), PRIMARY_OUTLET, 'someComponent', s);
new BehaviorSubject(null), new BehaviorSubject(null), new BehaviorSubject(null),
new BehaviorSubject(null), new BehaviorSubject(null), PRIMARY_OUTLET, 'someComponent', s);
advanceActivatedRoute(a);
return createUrlTree(a, tree, commands, queryParams !, fragment !);
return createUrlTree(a, tree, commands, queryParams, fragment);
}
function create(
@ -263,8 +263,8 @@ function create(
[], <any>{}, <any>{}, '', <any>{}, PRIMARY_OUTLET, 'someComponent', null, <any>segment,
startIndex, <any>null);
const a = new ActivatedRoute(
new BehaviorSubject(null !), new BehaviorSubject(null !), new BehaviorSubject(null !),
new BehaviorSubject(null !), new BehaviorSubject(null !), PRIMARY_OUTLET, 'someComponent', s);
new BehaviorSubject(null), new BehaviorSubject(null), new BehaviorSubject(null),
new BehaviorSubject(null), new BehaviorSubject(null), PRIMARY_OUTLET, 'someComponent', s);
advanceActivatedRoute(a);
return createUrlTree(a, tree, commands, queryParams !, fragment !);
return createUrlTree(a, tree, commands, queryParams, fragment);
}

View File

@ -240,7 +240,7 @@ describe('Integration', () => {
advance(fixture);
let recordedError: any = null;
router.navigateByUrl('/blank') !.catch(e => recordedError = e);
router.navigateByUrl('/blank').catch(e => recordedError = e);
advance(fixture);
expect(recordedError.message).toEqual('Cannot find primary outlet to load \'BlankCmp\'');
@ -620,8 +620,8 @@ describe('Integration', () => {
const user = fixture.debugElement.children[1].componentInstance;
let r1: any, r2: any;
router.navigateByUrl('/user/victor') !.then(_ => r1 = _);
router.navigateByUrl('/user/fedor') !.then(_ => r2 = _);
router.navigateByUrl('/user/victor').then(_ => r1 = _);
router.navigateByUrl('/user/fedor').then(_ => r2 = _);
advance(fixture);
expect(r1).toEqual(false); // returns false because it was canceled
@ -650,7 +650,7 @@ describe('Integration', () => {
router.events.forEach(e => recordedEvents.push(e));
let e: any;
router.navigateByUrl('/invalid') !.catch(_ => e = _);
router.navigateByUrl('/invalid').catch(_ => e = _);
advance(fixture);
expect(e.message).toContain('Cannot match any routes');
@ -677,7 +677,7 @@ describe('Integration', () => {
router.events.forEach(e => recordedEvents.push(e));
let e: any;
router.navigateByUrl('/invalid') !.then(_ => e = _);
router.navigateByUrl('/invalid').then(_ => e = _);
advance(fixture);
expect(e).toEqual('resolvedValue');
@ -911,7 +911,7 @@ describe('Integration', () => {
router.events.subscribe(e => recordedEvents.push(e));
let e: any = null;
router.navigateByUrl('/simple') !.catch(error => e = error);
router.navigateByUrl('/simple').catch(error => e = error);
advance(fixture);
expectEvents(recordedEvents, [
@ -1688,7 +1688,7 @@ describe('Integration', () => {
{
provide: 'RecordingDeactivate',
useValue: (c: any, a: ActivatedRouteSnapshot, b: RouterStateSnapshot) => {
log.push({path: a.routeConfig !.path, component: c});
log.push({path: a.routeConfig.path, component: c});
return true;
}
},
@ -1736,14 +1736,14 @@ describe('Integration', () => {
advance(fixture);
expect(location.path()).toEqual('/team/22');
let successStatus: boolean = false;
router.navigateByUrl('/team/33') !.then(res => successStatus = res);
let successStatus: boolean;
router.navigateByUrl('/team/33').then(res => successStatus = res);
advance(fixture);
expect(location.path()).toEqual('/team/33');
expect(successStatus).toEqual(true);
let canceledStatus: boolean = false;
router.navigateByUrl('/team/44') !.then(res => canceledStatus = res);
let canceledStatus: boolean;
router.navigateByUrl('/team/44').then(res => canceledStatus = res);
advance(fixture);
expect(location.path()).toEqual('/team/33');
expect(canceledStatus).toEqual(false);
@ -2073,7 +2073,7 @@ describe('Integration', () => {
expect(location.path()).toEqual('/team/22');
router.navigateByUrl('/team/33') !.catch(() => {});
router.navigateByUrl('/team/33').catch(() => {});
advance(fixture);
expect(location.path()).toEqual('/team/22');
@ -2582,8 +2582,8 @@ describe('Integration', () => {
expect(location.path()).toEqual('/lazy/parent/child');
expect(fixture.nativeElement).toHaveText('parent[child]');
const pInj = fixture.debugElement.query(By.directive(Parent)).injector !;
const cInj = fixture.debugElement.query(By.directive(Child)).injector !;
const pInj = fixture.debugElement.query(By.directive(Parent)).injector;
const cInj = fixture.debugElement.query(By.directive(Child)).injector;
expect(pInj.get('moduleName')).toEqual('parent');
expect(pInj.get('fromParent')).toEqual('from parent');
@ -2769,7 +2769,7 @@ describe('Integration', () => {
router.resetConfig([{path: 'lazy', loadChildren: 'expected'}]);
let recordedError: any = null;
router.navigateByUrl('/lazy/loaded') !.catch(err => recordedError = err);
router.navigateByUrl('/lazy/loaded').catch(err => recordedError = err);
advance(fixture);
expect(recordedError.message)
.toEqual(
@ -2942,7 +2942,7 @@ describe('Integration', () => {
const recordedEvents: any[] = [];
router.events.forEach(e => recordedEvents.push(e));
router.navigateByUrl('/lazy/loaded') !.catch(s => {});
router.navigateByUrl('/lazy/loaded').catch(s => {});
advance(fixture);
expect(location.path()).toEqual('/');
@ -3206,19 +3206,19 @@ describe('Integration', () => {
stored: {[k: string]: DetachedRouteHandle} = {};
shouldDetach(route: ActivatedRouteSnapshot): boolean {
return route.routeConfig !.path === 'a';
return route.routeConfig.path === 'a';
}
store(route: ActivatedRouteSnapshot, detachedTree: DetachedRouteHandle): void {
this.stored[route.routeConfig !.path !] = detachedTree;
this.stored[route.routeConfig.path] = detachedTree;
}
shouldAttach(route: ActivatedRouteSnapshot): boolean {
return !!this.stored[route.routeConfig !.path !];
return !!this.stored[route.routeConfig.path];
}
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle {
return this.stored[route.routeConfig !.path !];
return this.stored[route.routeConfig.path];
}
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
@ -3230,7 +3230,7 @@ describe('Integration', () => {
shouldDetach(route: ActivatedRouteSnapshot): boolean { return false; }
store(route: ActivatedRouteSnapshot, detachedTree: DetachedRouteHandle): void {}
shouldAttach(route: ActivatedRouteSnapshot): boolean { return false; }
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle { return null !; }
retrieve(route: ActivatedRouteSnapshot): DetachedRouteHandle { return null; }
shouldReuseRoute(future: ActivatedRouteSnapshot, curr: ActivatedRouteSnapshot): boolean {
if (future.routeConfig !== curr.routeConfig) {
return false;

View File

@ -16,14 +16,14 @@ describe('recognize', () => {
it('should work', () => {
checkRecognize([{path: 'a', component: ComponentA}], 'a', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.root, '', {}, RootComponent);
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);
checkActivatedRoute(s.firstChild(s.root), 'a', {}, ComponentA);
});
});
it('should freeze params object', () => {
checkRecognize([{path: 'a/:id', component: ComponentA}], 'a/10', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.root, '', {}, RootComponent);
const child = s.firstChild(s.root) !;
const child = s.firstChild(s.root);
expect(Object.isFrozen(child.params)).toBeTruthy();
});
});
@ -79,11 +79,11 @@ describe('recognize', () => {
expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1);
const compA = s.firstChild(s.root) !;
const compA = s.firstChild(s.root);
expect(compA._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
expect(compA._lastPathIndex).toBe(1);
const compC = s.firstChild(<any>compA) !;
const compC = s.firstChild(<any>compA);
expect(compC._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
expect(compC._lastPathIndex).toBe(2);
});
@ -101,11 +101,11 @@ describe('recognize', () => {
expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1);
const compA = s.firstChild(s.root) !;
const compA = s.firstChild(s.root);
expect(compA._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
expect(compA._lastPathIndex).toBe(0);
const compC = s.firstChild(<any>compA) !;
const compC = s.firstChild(<any>compA);
expect(compC._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
expect(compC._lastPathIndex).toBe(2);
});
@ -119,16 +119,16 @@ describe('recognize', () => {
],
'a/paramA', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.root, '', {}, RootComponent);
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);
checkActivatedRoute(s.firstChild(s.root), 'a', {}, ComponentA);
checkActivatedRoute(
s.firstChild(<any>s.firstChild(s.root)) !, 'paramA', {id: 'paramA'}, ComponentB);
s.firstChild(<any>s.firstChild(s.root)), 'paramA', {id: 'paramA'}, ComponentB);
});
checkRecognize(
[{path: 'a', component: ComponentA}, {path: 'a/:id', component: ComponentC}], 'a/paramA',
(s: RouterStateSnapshot) => {
checkActivatedRoute(s.root, '', {}, RootComponent);
checkActivatedRoute(s.firstChild(s.root) !, 'a/paramA', {id: 'paramA'}, ComponentC);
checkActivatedRoute(s.firstChild(s.root), 'a/paramA', {id: 'paramA'}, ComponentC);
});
});
@ -187,7 +187,7 @@ describe('recognize', () => {
'a;a1=11;a2=22/b;b1=111;b2=222(left:c;c1=1111;c2=2222)', (s: RouterStateSnapshot) => {
const c = s.children(s.root);
checkActivatedRoute(c[0], 'a', {a1: '11', a2: '22'}, ComponentA);
checkActivatedRoute(s.firstChild(<any>c[0]) !, 'b', {b1: '111', b2: '222'}, ComponentB);
checkActivatedRoute(s.firstChild(<any>c[0]), 'b', {b1: '111', b2: '222'}, ComponentB);
checkActivatedRoute(c[1], 'c', {c1: '1111', c2: '2222'}, ComponentC, 'left');
});
});
@ -196,7 +196,7 @@ describe('recognize', () => {
it('should set static data', () => {
checkRecognize(
[{path: 'a', data: {one: 1}, component: ComponentA}], 'a', (s: RouterStateSnapshot) => {
const r: ActivatedRouteSnapshot = s.firstChild(s.root) !;
const r: ActivatedRouteSnapshot = s.firstChild(s.root);
expect(r.data).toEqual({one: 1});
});
});
@ -209,7 +209,7 @@ describe('recognize', () => {
children: [{path: 'b', data: {two: 2}, component: ComponentB}]
}],
'a/b', (s: RouterStateSnapshot) => {
const r: ActivatedRouteSnapshot = s.firstChild(<any>s.firstChild(s.root)) !;
const r: ActivatedRouteSnapshot = s.firstChild(<any>s.firstChild(s.root));
expect(r.data).toEqual({one: 1, two: 2});
});
});
@ -218,7 +218,7 @@ describe('recognize', () => {
checkRecognize(
[{path: 'a', resolve: {one: 'some-token'}, component: ComponentA}], 'a',
(s: RouterStateSnapshot) => {
const r: ActivatedRouteSnapshot = s.firstChild(s.root) !;
const r: ActivatedRouteSnapshot = s.firstChild(s.root);
expect(r._resolve).toEqual({one: 'some-token'});
});
});
@ -228,7 +228,7 @@ describe('recognize', () => {
describe('root', () => {
it('should work', () => {
checkRecognize([{path: '', component: ComponentA}], '', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, '', {}, ComponentA);
checkActivatedRoute(s.firstChild(s.root), '', {}, ComponentA);
});
});
@ -236,7 +236,7 @@ describe('recognize', () => {
checkRecognize(
[{path: '', pathMatch: 'full', component: ComponentA}], '',
(s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, '', {}, ComponentA);
checkActivatedRoute(s.firstChild(s.root), '', {}, ComponentA);
});
});
@ -244,8 +244,8 @@ describe('recognize', () => {
checkRecognize(
[{path: '', component: ComponentA, children: [{path: '', component: ComponentB}]}], '',
(s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, '', {}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)) !, '', {}, ComponentB);
checkActivatedRoute(s.firstChild(s.root), '', {}, ComponentA);
checkActivatedRoute(s.firstChild(<any>s.firstChild(s.root)), '', {}, ComponentB);
});
});
@ -259,11 +259,11 @@ describe('recognize', () => {
expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1);
const c = s.firstChild(s.root) !;
const c = s.firstChild(s.root);
expect(c._urlSegment).toBe(url.root);
expect(c._lastPathIndex).toBe(-1);
const c2 = s.firstChild(<any>s.firstChild(s.root)) !;
const c2 = s.firstChild(<any>s.firstChild(s.root));
expect(c2._urlSegment).toBe(url.root);
expect(c2._lastPathIndex).toBe(-1);
});
@ -279,10 +279,10 @@ describe('recognize', () => {
]
}],
'/a;p=1', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a', {p: '1'}, ComponentA);
checkActivatedRoute(s.firstChild(s.firstChild(s.root) !) !, '', {p: '1'}, ComponentB);
checkActivatedRoute(s.firstChild(s.root), 'a', {p: '1'}, ComponentA);
checkActivatedRoute(s.firstChild(s.firstChild(s.root)), '', {p: '1'}, ComponentB);
checkActivatedRoute(
s.firstChild(s.firstChild(s.firstChild(s.root) !) !) !, '', {p: '1'}, ComponentC);
s.firstChild(s.firstChild(s.firstChild(s.root))), '', {p: '1'}, ComponentC);
});
});
});
@ -299,9 +299,9 @@ describe('recognize', () => {
]
}],
'a/b', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);
checkActivatedRoute(s.firstChild(s.root), 'a', {}, ComponentA);
const c = s.children(s.firstChild(s.root) !);
const c = s.children(s.firstChild(s.root));
checkActivatedRoute(c[0], 'b', {}, ComponentB);
checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');
});
@ -330,13 +330,13 @@ describe('recognize', () => {
checkRecognize(config, 'parent/b', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.root, '', {}, RootComponent);
checkActivatedRoute(s.firstChild(s.root) !, 'parent', {}, undefined !);
checkActivatedRoute(s.firstChild(s.root), 'parent', {}, undefined);
const cc = s.children(s.firstChild(s.root) !);
const cc = s.children(s.firstChild(s.root));
checkActivatedRoute(cc[0], '', {}, ComponentA);
checkActivatedRoute(cc[1], '', {}, ComponentD, 'secondary');
checkActivatedRoute(s.firstChild(cc[0]) !, 'b', {}, ComponentB);
checkActivatedRoute(s.firstChild(cc[0]), 'b', {}, ComponentB);
});
});
@ -351,9 +351,9 @@ describe('recognize', () => {
]
}],
'a/b', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);
checkActivatedRoute(s.firstChild(s.root), 'a', {}, ComponentA);
const c = s.children(s.firstChild(s.root) !);
const c = s.children(s.firstChild(s.root));
expect(c.length).toEqual(1);
checkActivatedRoute(c[0], 'b', {}, ComponentB);
});
@ -375,11 +375,11 @@ describe('recognize', () => {
expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1);
const a = s.firstChild(s.root) !;
const a = s.firstChild(s.root);
expect(a._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
expect(a._lastPathIndex).toBe(0);
const b = s.firstChild(a) !;
const b = s.firstChild(a);
expect(b._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
expect(b._lastPathIndex).toBe(1);
@ -403,15 +403,15 @@ describe('recognize', () => {
expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1);
const a = s.firstChild(s.root) !;
const a = s.firstChild(s.root);
expect(a._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
expect(a._lastPathIndex).toBe(0);
const b = s.firstChild(a) !;
const b = s.firstChild(a);
expect(b._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
expect(b._lastPathIndex).toBe(0);
const c = s.firstChild(b) !;
const c = s.firstChild(b);
expect(c._urlSegment).toBe(url.root.children[PRIMARY_OUTLET]);
expect(c._lastPathIndex).toBe(0);
});
@ -431,15 +431,15 @@ describe('recognize', () => {
expect(s.root._urlSegment).toBe(url.root);
expect(s.root._lastPathIndex).toBe(-1);
const a = s.firstChild(s.root) !;
const a = s.firstChild(s.root);
expect(a._urlSegment).toBe(url.root);
expect(a._lastPathIndex).toBe(-1);
const b = s.firstChild(a) !;
const b = s.firstChild(a);
expect(b._urlSegment).toBe(url.root);
expect(b._lastPathIndex).toBe(-1);
const c = s.firstChild(b) !;
const c = s.firstChild(b);
expect(c._urlSegment).toBe(url.root);
expect(c._lastPathIndex).toBe(-1);
});
@ -458,9 +458,9 @@ describe('recognize', () => {
]
}],
'a', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);
checkActivatedRoute(s.firstChild(s.root), 'a', {}, ComponentA);
const c = s.children(s.firstChild(s.root) !);
const c = s.children(s.firstChild(s.root));
checkActivatedRoute(c[0], '', {}, ComponentB);
checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');
});
@ -477,9 +477,9 @@ describe('recognize', () => {
]
}],
'a', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);
checkActivatedRoute(s.firstChild(s.root), 'a', {}, ComponentA);
const c = s.children(s.firstChild(s.root) !);
const c = s.children(s.firstChild(s.root));
checkActivatedRoute(c[0], '', {}, ComponentB);
checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');
});
@ -496,9 +496,9 @@ describe('recognize', () => {
]
}],
'a/(aux:c)', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);
checkActivatedRoute(s.firstChild(s.root), 'a', {}, ComponentA);
const c = s.children(s.firstChild(s.root) !);
const c = s.children(s.firstChild(s.root));
checkActivatedRoute(c[0], '', {}, ComponentB);
checkActivatedRoute(c[1], 'c', {}, ComponentC, 'aux');
});
@ -538,13 +538,13 @@ describe('recognize', () => {
]
}],
'a/(d//aux:e)', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a', {}, ComponentA);
checkActivatedRoute(s.firstChild(s.root), 'a', {}, ComponentA);
const c = s.children(s.firstChild(s.root) !);
const c = s.children(s.firstChild(s.root));
checkActivatedRoute(c[0], '', {}, ComponentB);
checkActivatedRoute(s.firstChild(c[0]) !, 'd', {}, ComponentD);
checkActivatedRoute(s.firstChild(c[0]), 'd', {}, ComponentD);
checkActivatedRoute(c[1], '', {}, ComponentC, 'aux');
checkActivatedRoute(s.firstChild(c[1]) !, 'e', {}, ComponentE);
checkActivatedRoute(s.firstChild(c[1]), 'e', {}, ComponentE);
});
});
});
@ -554,7 +554,7 @@ describe('recognize', () => {
it('should support simple wildcards', () => {
checkRecognize(
[{path: '**', component: ComponentA}], 'a/b/c/d;a1=11', (s: RouterStateSnapshot) => {
checkActivatedRoute(s.firstChild(s.root) !, 'a/b/c/d', {a1: '11'}, ComponentA);
checkActivatedRoute(s.firstChild(s.root), 'a/b/c/d', {a1: '11'}, ComponentA);
});
});
});
@ -570,8 +570,8 @@ describe('recognize', () => {
]
}],
'p/11;pp=22/(a;pa=33//aux:b;pb=44)', (s: RouterStateSnapshot) => {
const p = s.firstChild(s.root) !;
checkActivatedRoute(p, 'p/11', {id: '11', pp: '22'}, undefined !);
const p = s.firstChild(s.root);
checkActivatedRoute(p, 'p/11', {id: '11', pp: '22'}, undefined);
const c = s.children(p);
checkActivatedRoute(c[0], 'a', {id: '11', pp: '22', pa: '33'}, ComponentA);
@ -593,16 +593,16 @@ describe('recognize', () => {
}]
}],
'p/11/a/victor/b/c', (s: RouterStateSnapshot) => {
const p = s.firstChild(s.root) !;
checkActivatedRoute(p, 'p/11', {id: '11'}, undefined !);
const p = s.firstChild(s.root);
checkActivatedRoute(p, 'p/11', {id: '11'}, undefined);
const a = s.firstChild(p) !;
checkActivatedRoute(a, 'a/victor', {id: '11', name: 'victor'}, undefined !);
const a = s.firstChild(p);
checkActivatedRoute(a, 'a/victor', {id: '11', name: 'victor'}, undefined);
const b = s.firstChild(a) !;
const b = s.firstChild(a);
checkActivatedRoute(b, 'b', {id: '11', name: 'victor'}, ComponentB);
const c = s.firstChild(b) !;
const c = s.firstChild(b);
checkActivatedRoute(c, 'c', {}, ComponentC);
});
});
@ -614,7 +614,7 @@ describe('recognize', () => {
[{path: 'a', component: ComponentA, children: [{path: 'b', component: ComponentB}]}],
'/a', (s: RouterStateSnapshot) => {
const a = s.firstChild(s.root);
checkActivatedRoute(a !, 'a', {}, ComponentA);
checkActivatedRoute(a, 'a', {}, ComponentA);
});
});
@ -629,7 +629,7 @@ describe('recognize', () => {
]
}],
'/a', (s: RouterStateSnapshot) => {
const a = s.firstChild(s.root) !;
const a = s.firstChild(s.root);
checkActivatedRoute(a, 'a', {}, ComponentA);
checkActivatedRoute(a.children[0], '', {}, ComponentC, 'aux');
});
@ -651,11 +651,11 @@ describe('recognize', () => {
matcher: matcher,
component: ComponentA,
children: [{path: 'b', component: ComponentB}]
}] as any,
}],
'/a/1;p=99/b', (s: RouterStateSnapshot) => {
const a = s.root.firstChild !;
const a = s.root.firstChild;
checkActivatedRoute(a, 'a/1', {id: '1', p: '99'}, ComponentA);
checkActivatedRoute(a.firstChild !, 'b', {}, ComponentB);
checkActivatedRoute(a.firstChild, 'b', {}, ComponentB);
});
});
});

View File

@ -57,7 +57,7 @@ describe('Router', () => {
const inj = {get: (token: any) => () => `${token}_value`};
let empty: RouterStateSnapshot;
beforeEach(() => { empty = createEmptyStateSnapshot(serializer.parse('/'), null !); });
beforeEach(() => { empty = createEmptyStateSnapshot(serializer.parse('/'), null); });
it('should resolve data', () => {
const r = {data: 'resolver'};
@ -65,7 +65,7 @@ describe('Router', () => {
const s = new RouterStateSnapshot('url', new TreeNode(empty.root, [new TreeNode(n, [])]));
checkResolveData(s, empty, inj, () => {
expect(s.root.firstChild !.data).toEqual({data: 'resolver_value'});
expect(s.root.firstChild.data).toEqual({data: 'resolver_value'});
});
});
@ -73,7 +73,7 @@ describe('Router', () => {
const parentResolve = {data: 'resolver'};
const childResolve = {};
const parent = createActivatedRouteSnapshot(null !, {resolve: parentResolve});
const parent = createActivatedRouteSnapshot(null, {resolve: parentResolve});
const child = createActivatedRouteSnapshot('b', {resolve: childResolve});
const s = new RouterStateSnapshot(
@ -82,7 +82,7 @@ describe('Router', () => {
const inj = {get: (token: any) => () => Promise.resolve(`${token}_value`)};
checkResolveData(s, empty, inj, () => {
expect(s.root.firstChild !.firstChild !.data).toEqual({data: 'resolver_value'});
expect(s.root.firstChild.firstChild.data).toEqual({data: 'resolver_value'});
});
});
@ -99,8 +99,8 @@ describe('Router', () => {
const s2 = new RouterStateSnapshot(
'url', new TreeNode(empty.root, [new TreeNode(n21, [new TreeNode(n22, [])])]));
checkResolveData(s2, s1, inj, () => {
expect(s2.root.firstChild !.data).toEqual({data: 'resolver1_value'});
expect(s2.root.firstChild !.firstChild !.data).toEqual({data: 'resolver2_value'});
expect(s2.root.firstChild.data).toEqual({data: 'resolver1_value'});
expect(s2.root.firstChild.firstChild.data).toEqual({data: 'resolver2_value'});
});
});
});

View File

@ -39,17 +39,17 @@ describe('RouterState & Snapshot', () => {
});
it('should return root', () => {
const b = state.root.firstChild !;
const b = state.root.firstChild;
expect(b.root).toBe(state.root);
});
it('should return parent', () => {
const b = state.root.firstChild !;
const b = state.root.firstChild;
expect(b.parent).toBe(state.root);
});
it('should return path from root', () => {
const b = state.root.firstChild !;
const b = state.root.firstChild;
const p = b.pathFromRoot;
expect(p[0]).toBe(state.root);
expect(p[1]).toBe(b);
@ -81,17 +81,17 @@ describe('RouterState & Snapshot', () => {
});
it('should return root', () => {
const b = state.root.firstChild !;
const b = state.root.firstChild;
expect(b.root).toBe(state.root);
});
it('should return parent', () => {
const b = state.root.firstChild !;
const b = state.root.firstChild;
expect(b.parent).toBe(state.root);
});
it('should return path from root', () => {
const b = state.root.firstChild !;
const b = state.root.firstChild;
const p = b.pathFromRoot;
expect(p[0]).toBe(state.root);
expect(p[1]).toBe(b);
@ -102,7 +102,7 @@ describe('RouterState & Snapshot', () => {
function createSnapshot(params: Params, url: UrlSegment[]): ActivatedRouteSnapshot {
const snapshot = new ActivatedRouteSnapshot(
url, params, <any>null, <any>null, <any>null, <any>null, <any>null, <any>null, <any>null,
-1, null !);
-1, null);
snapshot._routerState = new RouterStateSnapshot('', new TreeNode(snapshot, []));
return snapshot;
}
@ -177,7 +177,7 @@ describe('RouterState & Snapshot', () => {
const data = {};
const snapshot = new ActivatedRouteSnapshot(
url, params, queryParams, fragment, data, <any>null, <any>null, <any>null, <any>null, -1,
null !);
null);
const state = new RouterStateSnapshot('', new TreeNode(snapshot, []));
snapshot._routerState = state;
return snapshot;
@ -200,7 +200,7 @@ describe('RouterState & Snapshot', () => {
function createActivatedRouteSnapshot(cmp: string) {
return new ActivatedRouteSnapshot(
<any>null, <any>null, <any>null, <any>null, <any>null, <any>null, <any>cmp, <any>null,
<any>null, -1, null !);
<any>null, -1, null);
}
function createActivatedRoute(cmp: string) {