Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@SkyZeroZx
Copy link
Contributor

@SkyZeroZx SkyZeroZx commented Oct 3, 2025

Adds a schematics migration to convert RouterTestingModule usages in test suites to RouterModule, and to add provideLocationMocks() when Location or LocationStrategy is imported and no custom providers exist.

Usage

ng g @angular/core:router-testing-migration 

Example

Before:

TestBed.configureTestingModule({
  imports: [RouterTestingModule.withRoutes(routes, { initialNavigation: 'enabledBlocking' })]
});

After:

TestBed.configureTestingModule({
  imports: [RouterModule.forRoot(routes, { initialNavigation: 'enabledBlocking' })],
});

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #54853

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

By default, the regex for the files should be .spec.ts.

Should we make this configurable by the user , since each user might want to set it up differently?

Additional question, would it be good to also consider migration for the HttpClientTestingModule, as a mode of this test migration or should we generate another independent one?

Introduces a schematic to replace deprecated router testing imports
@pullapprove pullapprove bot requested a review from JeanMeche October 3, 2025 02:00
@angular-robot angular-robot bot added detected: feature PR contains a feature commit area: migrations Issues related to `ng update`/`ng generate` migrations labels Oct 3, 2025
@ngbot ngbot bot added this to the Backlog milestone Oct 3, 2025
import { Location } from '@angular/common';

describe('test', () => {
let mockLocation : Location;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit heavy-handed. Most things about Location would be the same without provideLocationMocks. The two main things that differ would be: Location.path() when the path is empty returns '/' with the location mocks but returns '' without them. Second, SpyLocation is really the one that's not available unless provideLocationMocks is used, and specifically just SpyLocation.urlChanges.

I would propose adjusting the migration instead:

  1. Only provide location mocks if SpyLocation.urlChanges is used
  2. [Optional] attempt to update any Location.path() expectations to expect empty string instead of '/'. This is somewhat difficult since it differs between test frameworks. I could also see providing the mocks if there is a string literal anywhere in the file that is '/' along with some call to Location.path()
  3. Update the documentation for the migration to note these differences in functionality with and without provideLocationMocks.

Copy link
Contributor Author

@SkyZeroZx SkyZeroZx Oct 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated with the recommendations, the changes now comply with point 1.

Regarding point 2, it sounds interesting, but it would introduce additional complexity that may vary depending on the test framework. It could potentially be considered under a feature flag, though I’m not entirely sure if it might cause more issues.

Regarding point 3, I’ve mentioned it in the updated documentation, but I’m not sure if it should be more detailed. I could also expand the router testing section to cover the behavior of SpyLocation and provideLocationMocks, since I haven’t found documentation about them, and it might be worth adding this information.

packages/core/schematics/BUILD.bazel Outdated Show resolved Hide resolved
Introduces a schematic to replace deprecated router testing imports
@JeanMeche JeanMeche requested a review from atscott October 4, 2025 18:43
Copy link
Contributor

@atscott atscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@atscott atscott added feature Issue that requests a new feature action: merge The PR is ready for merge by the caretaker target: minor This PR is targeted for the next minor release labels Oct 13, 2025
@AndrewKushnir AndrewKushnir removed the request for review from JeanMeche October 13, 2025 18:08
@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository. The changes were merged into the following branches:

AndrewKushnir pushed a commit that referenced this pull request Oct 13, 2025
…#64217)

Introduces a schematic to replace deprecated router testing imports

PR Close #64217
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: migrations Issues related to `ng update`/`ng generate` migrations detected: feature PR contains a feature commit feature Issue that requests a new feature target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.