Migrate Angular router link tests to use RouterTestingHarness #2430
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request
🤨 Rationale
We have several tests that verify Angular router link behavior by clicking links and inspecting router state. These tests exhibit a couple problems:
[web-server]: 404: /_karma_webpack_/page1?param1=true
The root cause of these issues is that the tests are actually trying to navigate the page when the link is clicked.
👩💻 Implementation
In researching best practices for writing tests like this I learned that the
RouterTestingModule
we had been using has been deprecated and replaced with a more powerfulRouterTestingHarness
. This blog and video does a good job of explaining it, much better than the angular docs. The basic idea is that the harness sets up a parent component and router which host your component under test. When something tries to navigate the harness captures information about the navigation but doesn't actually navigate the page.The fixes in this PR are to use
RouterTestingHarness
instead ofRouterTestingModule
. This has these side effects:provideRouter
instead ofwithRoutes
/start
and clicking a link topage
resulted in a URL of/start/page
. The simplest fix I found for this was to change the starting page to/
.🧪 Testing
✅ Checklist