-
Notifications
You must be signed in to change notification settings - Fork 92
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
feat: Added initialRoute parameter to avoid resolver issues with using a default route #367
Changes from 1 commit
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 | ||||
---|---|---|---|---|---|---|
|
@@ -12,6 +12,7 @@ import { | |||||
import { NoopAnimationsModule, BrowserAnimationsModule } from '@angular/platform-browser/animations'; | ||||||
import { TestBed } from '@angular/core/testing'; | ||||||
import { render, fireEvent, screen } from '../src/public_api'; | ||||||
import { Resolve, RouterModule } from '@angular/router'; | ||||||
|
||||||
@Component({ | ||||||
selector: 'atl-fixture', | ||||||
|
@@ -296,3 +297,49 @@ describe('DebugElement', () => { | |||||
expect(view.debugElement.componentInstance).toBeInstanceOf(FixtureComponent); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe('initialRoute', () => { | ||||||
@Component({ | ||||||
standalone: true, | ||||||
selector: 'atl-fixture2', | ||||||
template: `<button>Secondary Component</button>`, | ||||||
}) | ||||||
class SecondaryFixtureComponent {} | ||||||
|
||||||
@Component({ | ||||||
standalone: true, | ||||||
selector: 'atl-router-fixture', | ||||||
template: `<router-outlet></router-outlet>`, | ||||||
imports: [RouterModule], | ||||||
}) | ||||||
class RouterFixtureComponent {} | ||||||
|
||||||
@Injectable() | ||||||
class FixtureResolver implements Resolve<void> { | ||||||
public isResolved = false; | ||||||
|
||||||
public resolve() { | ||||||
this.isResolved = true; | ||||||
} | ||||||
} | ||||||
|
||||||
it('allows initially rendering a specific route to avoid triggering a resolver for the default route', async () => { | ||||||
const expectedRoute = 'correct-route'; | ||||||
const routes = [ | ||||||
{ path: expectedRoute, component: FixtureComponent }, | ||||||
{ path: '**', resolve: { data: FixtureResolver }, component: SecondaryFixtureComponent }, | ||||||
]; | ||||||
|
||||||
await render(RouterFixtureComponent, { | ||||||
initialRoute: expectedRoute, | ||||||
routes, | ||||||
detectChangesOnRender: false, | ||||||
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. Is there a reason why detect changes is set to false?
Suggested change
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. Mainly just to isolate the test from any extra logic, but I can remove it since it doesn't add any value here |
||||||
providers: [FixtureResolver], | ||||||
}); | ||||||
const resolver = TestBed.inject(FixtureResolver); | ||||||
|
||||||
expect(resolver.isResolved).toBe(false); | ||||||
expect(screen.queryByText('Secondary Component')).not.toBeInTheDocument(); | ||||||
expect(await screen.findByText('button')).toBeInTheDocument(); | ||||||
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. There's no need to await here.
Suggested change
|
||||||
}); | ||||||
}); |
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.
Could you rename this to the following please.
I do think it makes it intention clearer.