Repository navigation
feat(router) added method to convert an Url to RouterStateSnapshot #15826
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,36 @@ describe('Router', () => { | |
| })); | ||
| }); | ||
|
|
||
| describe('urlToRouteStateSnapshot', () => { | ||
| beforeEach(() => { TestBed.configureTestingModule({imports: [RouterTestingModule]}); }); | ||
|
|
||
| it('should return snapshot or exception', inject([Router], (r: Router) => { | ||
| r.resetConfig([ | ||
| { | ||
| path: 'a', | ||
| component: ComponentA, | ||
| data: {state: 'i am A'}, | ||
| children: [{path: 'b', component: ComponentB, data: {state: 'i am B'}}] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's also add a test for lazy loaded modules. Even if it doesn't work (though I don't immediately see why it wouldn't), the test documents the behavior. It does seem to me like this would actually trigger the lazy loading. If that's true, this needs to be documented. |
||
| }, | ||
| {path: 'c', component: ComponentC, data: {state: 'i am C'}} | ||
| ]); | ||
|
|
||
| r.urlToRouteStateSnapshot('/a').then( | ||
| (s) => { expect(s.root.firstChild !.data).toEqual({state: 'i am A'}); }); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, do these asynchronous expectations actually work reliably? I think nowadays we should use async/await instead, as doing so will return a Promise to jasmine which it will wait for.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No they don't, tested it |
||
|
|
||
| r.urlToRouteStateSnapshot('/a/b').then( | ||
| (s) => { expect(s.root.firstChild !.firstChild !.data).toEqual({state: 'i am B'}); }); | ||
|
|
||
| r.urlToRouteStateSnapshot('/c').then( | ||
| (s) => { expect(s.root.firstChild !.data).toEqual({state: 'i am C'}); }); | ||
|
|
||
| r.urlToRouteStateSnapshot('/x').catch((s => { | ||
| expect(s.toString()).toContain('Error: Cannot match any routes. URL Segment: \'x\''); | ||
| })); | ||
|
|
||
| })); | ||
| }); | ||
|
|
||
| describe('PreActivation', () => { | ||
| const serializer = new DefaultUrlSerializer(); | ||
| const inj = {get: (token: any) => () => `${token}_value`}; | ||
|
|
@@ -367,3 +397,7 @@ function checkGuards( | |
| p.initalize(new ChildrenOutletContexts()); | ||
| p.checkGuards().subscribe(check, (e) => { throw e; }); | ||
| } | ||
|
|
||
| class ComponentA {} | ||
| class ComponentB {} | ||
| class ComponentC {} | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just leave it as an
Observableand let the caller decide if they want to usetoPromiseor not?