Make the ComponentFixture public in new RouterTestingHarness

This issue has been tracked since 2023-01-26.

Which @angular/* package(s) are relevant/related to the feature request?

No response

Description

The RouterTestingHarness which just landed in the main branch looks great, but if I understand correctly, it creates a ComponentFixture and keeps it private.

This makes it impossible to use some of the methods/properties that ComponentFixture exposes in tests using the RouterTestingHarness.
And this also makes it harder to use existing testing libraries which are built on top of ComponentFixture, such as ngx-speculoos.

It would be nice if the RouterTestingHarness exposed the root ComponentFixture publicly instead of keeping it private.

Proposed solution

Expose the ComponentFixture publicly in RouterTestingHarness

Alternatives considered

  • cheat and access the property even though it's private, but that is of course not desirable.
  • reimplement the same kind of harness, but with a public component fixture. That is also not very desirable.
atscott wrote this answer on 2023-01-29

Thanks for the feedback. ComponentFixture was initially exposed but got removed after some rounds of public API review.

This makes it impossible to use some of the methods/properties that ComponentFixture exposes in tests using the RouterTestingHarness.

Could you expand on this a bit? Which methods/properties, specifically? We felt that what was exposed would satisfy the necessary use-cases. Most of the helper methods not exposed from ComponentFixture are just wrappers around things you can already do with public API. Granted, if you wanted those specific features, it'd be a lot more verbose to rewrite them by hand, but I'd be curious about the specific use-cases. I would guess this comes down more to integrating with existing tooling written around ComponentFixture interface/instance.

And this also makes it harder to use existing testing libraries which are built on top of ComponentFixture, such as ngx-speculoos.

What's exposed in the harness would be enough to technically work with ngx-speculoos, but I agree that this isn't a good answer. ComponentFixture seems the best way to be compatible with community tooling, including test harnesses from the CDK. Those harnesses use componentRef and whenStable from the fixture, which aren't exposed in the router testing harness.

// cc @alxhub

jnizet wrote this answer on 2023-01-29

Regarding the additional methods, I was mainly thinking about whenStable. But to be honest, the main reason I asked for this feature is the integration with ngx-speculoos, whose ComponentTester base class expects a ComponentFixture.

MikaStark wrote this answer on 2023-03-13

This is also required for TestbedHarnessEnvironment#loader from @angular/material

More Details About Repo
Owner Name angular
Repo Name angular
Full Name angular/angular
Language TypeScript
Created Date 2014-09-18
Updated Date 2023-03-21
Star Count 87006
Watcher Count 3028
Fork Count 23170
Issue Count 1418

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date