RouterTestingHarness
A testing harness for the Router
to reduce the boilerplate needed to test routes and routed
components.
class RouterTestingHarness {
static create(initialUrl?: string): Promise<RouterTestingHarness>
fixture: ComponentFixture<unknown>
routeDebugElement: DebugElement | null
routeNativeElement: HTMLElement | null
detectChanges(): void
navigateByUrl<T>(url: string, requiredRoutedComponentType?: Type<T>): Promise<T | null>
navigateByUrl(url: string): Promise<null | {}>
navigateByUrl<T>(url: string, requiredRoutedComponentType: Type<T>): Promise<T>
}
Static methods
create() | |||
---|---|---|---|
Creates a |
|||
Parameters
Returns
|
|||
The Throws an error if an instance has already been created.
Use of this harness also requires |
Properties
Property | Description |
---|---|
fixture: ComponentFixture<unknown>
|
Read-Only
Fixture of the root component of the RouterTestingHarness |
routeDebugElement: DebugElement | null
|
Read-Only
The |
routeNativeElement: HTMLElement | null
|
Read-Only
The native element of the |
Methods
detectChanges() |
---|
Instructs the root fixture to run change detection. |
ParametersThere are no parameters. Returns
|
navigateByUrl() | ||||||
---|---|---|---|---|---|---|
Triggers a
Parameters
Returns
|
||||||
Triggers a router navigation and waits for it to complete.
Parameters
Returns
The root component with a
The root component is reused within the same test in subsequent calls to This function also makes it easier to test components that depend on
|
||||||
The root component with a When testing
|