Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Angular’s official migration schematic replaces test uses of RouterTestingModule with RouterModule. Run ng generate @angular/core:router-testing-module-migration; it can also add provideLocationMocks() when a test imports SpyLocation and reads urlChanges. Its documented conversion is module-based, not a universal rewrite to provideRouter.
Run the RouterTestingModule migration
From the Angular workspace, run:
ng generate @angular/core:router-testing-module-migration
The schematic migrates RouterTestingModule usages inside tests to RouterModule. To target only part of a project, pass --path with a path relative to the project root. The option defaults to ./, so you can migrate a subset before running it across the workspace. See Angular’s Router Testing Module Migration guide.
As an Amazon Associate I earn from qualifying purchases.
What the schematic changes
Route configuration and options
For a test using RouterTestingModule.withRoutes(routes, options), Angular documents replacing it with RouterModule.forRoot(routes, options). The route array and options are carried into the new call. For example, a test configured with blocking initial navigation becomes:
import { RouterModule } from '@angular/router';
TestBed.configureTestingModule({
imports: [
RouterModule.forRoot(routes, { initialNavigation: 'enabledBlocking' }),
],
});
This preserves the demonstrated initialNavigation setting as well as the routes. Review the migrated test’s imports and configuration if it uses other options; do not assume an unrelated provider-based rewrite has occurred. The before-and-after pattern is shown in the migration guide.
#1 Best Overall
Tests that inspect URL changes
Angular documents a specific location-mock case: when a test imports SpyLocation from @angular/common/testing and uses its urlChanges property, the schematic adds provideLocationMocks() to the TestBed providers to preserve that behavior. The helper is imported from @angular/common/testing:
import { provideLocationMocks } from '@angular/common/testing';
TestBed.configureTestingModule({
providers: [provideLocationMocks()],
});
This is a targeted compatibility measure, not a requirement for every test that uses routing. Add or retain location mocks when the test relies on the mock location behavior, particularly the documented SpyLocation.urlChanges use.
Rank #2
RouterModule migration versus provideRouter
provideRouter configures routing through providers and has feature helpers for settings such as initial navigation and router configuration. It can fit applications and tests built around environment providers, but Angular’s migration example maps RouterTestingModule.withRoutes to RouterModule.forRoot; it does not prescribe a complete conversion of every test to provideRouter. Check the API available in the project’s Angular version and match the test’s existing setup.
| Question | Documented RouterModule migration | Provider-based setup |
|---|---|---|
| How routing is configured | Imports RouterModule.forRoot(routes, options) in the test module. |
Provides the router with provideRouter and applicable feature helpers. |
| Where routes and options go | The documented example carries the route array and ExtraOptions into forRoot. |
Configure routes and features using APIs supported by the project’s Angular version; the migration example does not prescribe a universal mapping. |
| Location behavior | The schematic adds provideLocationMocks() for its documented SpyLocation.urlChanges case. |
Keep location mocks if the test depends on that behavior; router providers alone are not a substitute for the documented mock. |
| Best fit | Tests already using NgModule imports and the schematic’s documented replacement. | Tests organized around provider-based or standalone configuration, after verifying version compatibility. |
The provider helpers are documented in Angular’s router provider API source. That URL tracks the main branch, so confirm the APIs against the release used by your project.
Rank #3
Deprecation and version context
Angular’s v18 API reference labels RouterTestingModule deprecated and lists withRoutes(routes, config?). The current migration catalog describes replacing its test usages with RouterModule, with location mocks added when the documented condition applies. Use the migration path supported by your Angular version rather than treating the deprecation label as evidence that every project should adopt the same provider configuration. See the Angular v18 RouterTestingModule API reference and Angular migrations overview.
Quick Recap
Rank #4
Verify the migrated tests
- Run the schematic at the workspace root, or use
--pathto start with a project subset. - Inspect the changed TestBed imports and providers. Confirm routes and options, including initial-navigation settings, remain present.
- Check tests that import
SpyLocationand useurlChangesfor the generatedprovideLocationMocks()provider. - Run the affected test suite. If a test uses provider-based setup or other router features, verify those APIs against the project’s Angular release and adapt that test deliberately rather than assuming the schematic converted it.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




