Sitelet https://github.com/angular/angular/pull/39096
Skip to content

fix(router): properly assign ExtraOptions to Router in RouterTestingModule - #39096

Closed
zelliott wants to merge 1 commit into
angular:masterfrom
zelliott:router
Closed

zelliott wants to merge 1 commit into
angular:masterfrom
zelliott:router

Conversation

@zelliott

@zelliott zelliott commented Oct 2, 2020 •

Copy link
Copy Markdown
Contributor

Previously, RouterTestingModule only assigned two of the options within ExtraOptions to the router. Now, it assigns the same options as RouterModule does (with the exception of enableTracing at the request of @atscott) via a new shared function assignExtraOptionsToRouter.

Fixes #23347

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.io application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Setting many of the options within ExtraOptions in the config for RouterTestingModule did not actually update the router's config (e.g. onSameUrlNavigation).

Issue Number: #23347

What is the new behavior?

The same options can now be properly set on both RouterModule and RouterTestingModule (with the exception of enableTracing).

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@atscott atscott left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @zelliott, thanks for the PR. As mentioned in the last comment on the bug, there are actually several options that don't make it from ExtraOptions to the router when using RouterTestingModule. I think we should address those as well.

It might be a good idea to create a function in router_module like assignExtraOptionsToRouterFields(router: Router, options: ExtraOptions) { ... } and share the code for the RouterModule implementation and the RouterTestingModule

if (urlHandlingStrategy) {
router.urlHandlingStrategy = urlHandlingStrategy;
}
if (routeReuseStrategy) {
router.routeReuseStrategy = routeReuseStrategy;
}
if (opts.errorHandler) {
router.errorHandler = opts.errorHandler;
}
if (opts.malformedUriErrorHandler) {
router.malformedUriErrorHandler = opts.malformedUriErrorHandler;
}
if (opts.enableTracing) {
const dom = getDOM();
router.events.subscribe((e: Event) => {
dom.logGroup(`Router Event: ${(<any>e.constructor).name}`);
dom.log(e.toString());
dom.log(e);
dom.logGroupEnd();
});
}
if (opts.onSameUrlNavigation) {
router.onSameUrlNavigation = opts.onSameUrlNavigation;
}
if (opts.paramsInheritanceStrategy) {
router.paramsInheritanceStrategy = opts.paramsInheritanceStrategy;
}
if (opts.urlUpdateStrategy) {
router.urlUpdateStrategy = opts.urlUpdateStrategy;
}
if (opts.relativeLinkResolution) {
router.relativeLinkResolution = opts.relativeLinkResolution;
}
(excluding enableTracing)

@atscott atscott added area: router target: patch This PR is targeted for the next patch release labels Oct 2, 2020
@ngbot ngbot Bot modified the milestone: needsTriage Oct 2, 2020
@atscott atscott added the action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews label Oct 2, 2020
@zelliott zelliott changed the title fix(router) onSameUrlNavigation config is now passed through RouterTestingModule fix(router): properly assign ExtraOptions to Router in RouterTestingModule Oct 3, 2020
@zelliott
zelliott force-pushed the router branch 3 times, most recently from 0d8595d to 320c44a Compare October 3, 2020 16:21
@zelliott

zelliott commented Oct 3, 2020

Copy link
Copy Markdown
Contributor Author

As mentioned in the last comment on the bug, there are actually several options that don't make it from ExtraOptions to the router when using RouterTestingModule. I think we should address those as well.

Done, PTAL.

@zelliott
zelliott requested a review from atscott October 3, 2020 16:43

@atscott atscott left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One small nit on the test organization but otherwise LGTM. presubmit. Starting global as well.

We might want to consider adding a breaking change note even though it's pretty unlikely/rare that this would break people. Something like
"BREAKING CHANGE: The RouterTestingModule now correctly assigns errorHandler, urlUpdateSstraategy, (...etc) from the ExtraOptions to the test module rather than just malformedUriErrorHandler and paramsInheritanceStrategy. If your test is setting these options, they will now be applied to navigations where they were ignored before and could result in a change in test behavior."

Comment thread packages/router/test/integration.spec.ts Outdated
@atscott atscott added action: presubmit The PR is in need of a google3 presubmit target: major This PR is targeted for the next major release and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews target: patch This PR is targeted for the next patch release labels Oct 5, 2020

@IgorMinar IgorMinar left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thank you

…odule

Previously, RouterTestingModule only assigned two of the options within ExtraOptions to the Router.
Now, it assigns the same options as RouterModule does (with the exception of enableTracing) via a
new shared function assignExtraOptionsToRouter.

Fixes angular#23347
@atscott

atscott commented Oct 5, 2020

Copy link
Copy Markdown
Contributor

global presubmit shows no related failures (1 test failed, but it's already failing at head). Marking as merge ready.

@atscott atscott added action: merge The PR is ready for merge by the caretaker and removed action: presubmit The PR is in need of a google3 presubmit labels Oct 5, 2020
@angular-automatic-lock-bot

Copy link
Copy Markdown

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 5, 2020
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: router cla: yes target: major This PR is targeted for the next major release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GST-14 ⁃ onSameUrlNavigation config value not set by RouterTestingModule

4 participants