-
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
feat: Added initialRoute parameter to avoid resolver issues with using a default route #367
Conversation
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.
Thanks, I like it!
} | ||
|
||
it('allows initially rendering a specific route to avoid triggering a resolver for the default route', async () => { | ||
const expectedRoute = 'correct-route'; |
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.
const expectedRoute = 'correct-route'; | |
const initialRoute = 'initial-route'; |
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
There's no need to await here.
expect(await screen.findByText('button')).toBeInTheDocument(); | |
expect(screen.getByText('button')).toBeInTheDocument(); |
await render(RouterFixtureComponent, { | ||
initialRoute: expectedRoute, | ||
routes, | ||
detectChangesOnRender: false, |
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.
Is there a reason why detect changes is set to false?
detectChangesOnRender: false, |
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.
Mainly just to isolate the test from any extra logic, but I can remove it since it doesn't add any value here
Just updated the tests based on your suggestions! |
@all-contributors please add @JJosephttg for code, tests |
@JJosephttg already contributed before to code, test |
Added the ability to specify an initial route to render with. As someone who wanted to use my original routes in my tests, I found that even though I do initial navigation without detecting changes in my tests using navigate, I would still run into issues where my resolver would get triggered despite the fact I was switching before detecting changes.
This allows navigation to happen before the location listener is set up so that you may perform an initial route navigation without causing any resolvers/guards to run and additionally having to specify await navigate(...) in your tests