RouterTestingHarness
A testing harness for the Router to reduce the boilerplate needed to test routes and routed
components.
API
class RouterTestingHarness { constructor(fixture: ComponentFixture<{ routerOutletData: WritableSignal<unknown>; }>): RouterTestingHarness; readonly fixture: ComponentFixture<{ routerOutletData: WritableSignal<unknown>; }>; detectChanges(): void; readonly routeDebugElement: DebugElement | null; readonly routeNativeElement: HTMLElement | null; navigateByUrl(url: string): Promise<{} | null>; navigateByUrl<T>(url: string, requiredRoutedComponentType: Type<T>): Promise<T>; static create(initialUrl?: string | undefined): Promise<RouterTestingHarness>;}
constructor
RouterTestingHarnessRouterTestingHarnessfixture
ComponentFixture<{ routerOutletData: WritableSignal<unknown>; }>Fixture of the root component of the RouterTestingHarness
detectChanges
voidInstructs the root fixture to run change detection.
voidrouteDebugElement
DebugElement | nullThe DebugElement of the RouterOutlet component. null if the outlet is not activated.
routeNativeElement
HTMLElement | nullThe native element of the RouterOutlet component. null if the outlet is not activated.
create
Promise<RouterTestingHarness>Creates a RouterTestingHarness instance.
The RouterTestingHarness also creates its own root component with a RouterOutlet for the
purposes of rendering route components.
Throws an error if an instance has already been created.
Use of this harness also requires destroyAfterEach: true in the ModuleTeardownOptions
string | undefinedThe target of navigation to trigger before returning the harness.
Promise<RouterTestingHarness>