1 | /**
|
2 | * @license Angular v15.2.3
|
3 | * (c) 2010-2022 Google LLC. https://angular.io/
|
4 | * License: MIT
|
5 | */
|
6 |
|
7 |
|
8 | import { ChildrenOutletContexts } from '@angular/router';
|
9 | import { Compiler } from '@angular/core';
|
10 | import { DebugElement } from '@angular/core';
|
11 | import { ExtraOptions } from '@angular/router';
|
12 | import * as i0 from '@angular/core';
|
13 | import * as i1 from '@angular/router';
|
14 | import { Injector } from '@angular/core';
|
15 | import { Location as Location_2 } from '@angular/common';
|
16 | import { ModuleWithProviders } from '@angular/core';
|
17 | import { Route } from '@angular/router';
|
18 | import { Router } from '@angular/router';
|
19 | import { RouteReuseStrategy } from '@angular/router';
|
20 | import { Routes } from '@angular/router';
|
21 | import { TitleStrategy } from '@angular/router';
|
22 | import { Type } from '@angular/core';
|
23 | import { UrlHandlingStrategy } from '@angular/router';
|
24 | import { UrlSerializer } from '@angular/router';
|
25 |
|
26 | /**
|
27 | * A testing harness for the `Router` to reduce the boilerplate needed to test routes and routed
|
28 | * components.
|
29 | *
|
30 | * @publicApi
|
31 | */
|
32 | export declare class RouterTestingHarness {
|
33 | private readonly fixture;
|
34 | /**
|
35 | * Creates a `RouterTestingHarness` instance.
|
36 | *
|
37 | * The `RouterTestingHarness` also creates its own root component with a `RouterOutlet` for the
|
38 | * purposes of rendering route components.
|
39 | *
|
40 | * Throws an error if an instance has already been created.
|
41 | * Use of this harness also requires `destroyAfterEach: true` in the `ModuleTeardownOptions`
|
42 | *
|
43 | * @param initialUrl The target of navigation to trigger before returning the harness.
|
44 | */
|
45 | static create(initialUrl?: string): Promise<RouterTestingHarness>;
|
46 | /** Instructs the root fixture to run change detection. */
|
47 | detectChanges(): void;
|
48 | /** The `DebugElement` of the `RouterOutlet` component. `null` if the outlet is not activated. */
|
49 | get routeDebugElement(): DebugElement | null;
|
50 | /** The native element of the `RouterOutlet` component. `null` if the outlet is not activated. */
|
51 | get routeNativeElement(): HTMLElement | null;
|
52 | /**
|
53 | * Triggers a `Router` navigation and waits for it to complete.
|
54 | *
|
55 | * The root component with a `RouterOutlet` created for the harness is used to render `Route`
|
56 | * components. The root component is reused within the same test in subsequent calls to
|
57 | * `navigateForTest`.
|
58 | *
|
59 | * When testing `Routes` with a guards that reject the navigation, the `RouterOutlet` might not be
|
60 | * activated and the `activatedComponent` may be `null`.
|
61 | *
|
62 | * {@example router/testing/test/router_testing_harness_examples.spec.ts region='Guard'}
|
63 | *
|
64 | * @param url The target of the navigation. Passed to `Router.navigateByUrl`.
|
65 | * @returns The activated component instance of the `RouterOutlet` after navigation completes
|
66 | * (`null` if the outlet does not get activated).
|
67 | */
|
68 | navigateByUrl(url: string): Promise<null | {}>;
|
69 | /**
|
70 | * Triggers a router navigation and waits for it to complete.
|
71 | *
|
72 | * The root component with a `RouterOutlet` created for the harness is used to render `Route`
|
73 | * components.
|
74 | *
|
75 | * {@example router/testing/test/router_testing_harness_examples.spec.ts region='RoutedComponent'}
|
76 | *
|
77 | * The root component is reused within the same test in subsequent calls to `navigateByUrl`.
|
78 | *
|
79 | * This function also makes it easier to test components that depend on `ActivatedRoute` data.
|
80 | *
|
81 | * {@example router/testing/test/router_testing_harness_examples.spec.ts region='ActivatedRoute'}
|
82 | *
|
83 | * @param url The target of the navigation. Passed to `Router.navigateByUrl`.
|
84 | * @param requiredRoutedComponentType After navigation completes, the required type for the
|
85 | * activated component of the `RouterOutlet`. If the outlet is not activated or a different
|
86 | * component is activated, this function will throw an error.
|
87 | * @returns The activated component instance of the `RouterOutlet` after navigation completes.
|
88 | */
|
89 | navigateByUrl<T>(url: string, requiredRoutedComponentType: Type<T>): Promise<T>;
|
90 | }
|
91 |
|
92 | /**
|
93 | * @description
|
94 | *
|
95 | * Sets up the router to be used for testing.
|
96 | *
|
97 | * The modules sets up the router to be used for testing.
|
98 | * It provides spy implementations of `Location` and `LocationStrategy`.
|
99 | *
|
100 | * @usageNotes
|
101 | * ### Example
|
102 | *
|
103 | * ```
|
104 | * beforeEach(() => {
|
105 | * TestBed.configureTestingModule({
|
106 | * imports: [
|
107 | * RouterTestingModule.withRoutes(
|
108 | * [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}]
|
109 | * )
|
110 | * ]
|
111 | * });
|
112 | * });
|
113 | * ```
|
114 | *
|
115 | * @publicApi
|
116 | */
|
117 | export declare class RouterTestingModule {
|
118 | static withRoutes(routes: Routes, config?: ExtraOptions): ModuleWithProviders<RouterTestingModule>;
|
119 | static ɵfac: i0.ɵɵFactoryDeclaration<RouterTestingModule, never>;
|
120 | static ɵmod: i0.ɵɵNgModuleDeclaration<RouterTestingModule, never, never, [typeof i1.RouterModule]>;
|
121 | static ɵinj: i0.ɵɵInjectorDeclaration<RouterTestingModule>;
|
122 | }
|
123 |
|
124 | /**
|
125 | * Router setup factory function used for testing.
|
126 | *
|
127 | * @publicApi
|
128 | * @deprecated Use `provideRouter` or `RouterTestingModule` instead.
|
129 | */
|
130 | export declare function setupTestingRouter(urlSerializer: UrlSerializer, contexts: ChildrenOutletContexts, location: Location_2, compiler: Compiler, injector: Injector, routes: Route[][], opts?: ExtraOptions | UrlHandlingStrategy | null, urlHandlingStrategy?: UrlHandlingStrategy, routeReuseStrategy?: RouteReuseStrategy, titleStrategy?: TitleStrategy): Router;
|
131 |
|
132 | export { }
|