Skip to content

fix routed components#25

Merged
shairez merged 1 commit into
mainfrom
pr-fix-routed
Mar 18, 2026
Merged

fix routed components#25
shairez merged 1 commit into
mainfrom
pr-fix-routed

Conversation

@shairez
Copy link
Copy Markdown
Contributor

@shairez shairez commented Mar 15, 2026

Summary

  • Fix: componentClassInstance and fixture now refer to the activated route’s component when using withRouting.

  • Feature: New disableInputBinding option in routing config to opt out of automatic route → input binding.


Changes

Fix: Activated route component in render result (patch)

When rendering with withRouting, the returned componentClassInstance and fixture now match the component that Angular Router activated for the current route.

Previously they could refer to a different component than the one rendered for the route. Assertions on componentClassInstance (e.g. route params like userId) and fixture access now behave as expected.

Feature: disableInputBinding for withRouting (minor)

Routing tests use Angular’s withComponentInputBinding() by default (route params, query params, and route data are bound to component inputs).

You can now pass disableInputBinding: true in the routing config to disable this. The router is then provided without withComponentInputBinding(), so components receive their default input values instead of values from the route. Useful when driving behavior only via ActivatedRoute or when you need to avoid automatic binding in specific tests.

@shairez shairez requested review from Copilot and yjaaidi March 15, 2026 13:22
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 15, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vitest-browser-angular@25

commit: a18ba9d

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the library’s render() helper to better support Angular Router-based tests by using RouterTestingHarness as the source of truth when routing is enabled, and by enabling withComponentInputBinding() by default (with an opt-out).

Changes:

  • Update render() to use RouterTestingHarness for fixture, container/locator, and componentClassInstance when withRouting is enabled.
  • Enable withComponentInputBinding() by default for routing tests; add disableInputBinding to opt out.
  • Expand tests and README docs to cover route params and input binding via route data.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/pure.ts Implements routing-mode rendering via RouterTestingHarness, adds input binding toggle, and extends result shape.
test/routed.test.ts Updates routing tests to use locator and adds coverage for route params + input binding behaviors.
test/components/routed.component.ts Adds a routed test component that reads a route param via ActivatedRoute.
README.md Updates code formatting and adds/updates routing documentation and examples.
.changeset/plain-parrots-double.md Patch changeset describing the routing render “fix”.
.changeset/eleven-jokes-burn.md Minor changeset describing the new input binding feature + opt-out.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/pure.ts
Comment thread src/pure.ts
Comment thread README.md
Copy link
Copy Markdown
Contributor

@yjaaidi yjaaidi left a comment

Choose a reason for hiding this comment

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

🚀 LGTM. Good job buddy!

IMO, this highlights that render is doing too much and that we should either have a different API for router testing or just let users use the router harness directly.
For now, let's just keep this as is. We'll get back to this in the upcoming RFCs 😉

@shairez
Copy link
Copy Markdown
Contributor Author

shairez commented Mar 18, 2026

thanks for the review @yjaaidi !
good observation, we'll brainstorm together

@shairez shairez merged commit 767fbf2 into main Mar 18, 2026
7 checks passed
@github-actions github-actions Bot mentioned this pull request Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants