UNPKG

5.54 kBTypeScriptView Raw
1/**
2 * @license Angular v15.2.3
3 * (c) 2010-2022 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7
8import { ChildrenOutletContexts } from '@angular/router';
9import { Compiler } from '@angular/core';
10import { DebugElement } from '@angular/core';
11import { ExtraOptions } from '@angular/router';
12import * as i0 from '@angular/core';
13import * as i1 from '@angular/router';
14import { Injector } from '@angular/core';
15import { Location as Location_2 } from '@angular/common';
16import { ModuleWithProviders } from '@angular/core';
17import { Route } from '@angular/router';
18import { Router } from '@angular/router';
19import { RouteReuseStrategy } from '@angular/router';
20import { Routes } from '@angular/router';
21import { TitleStrategy } from '@angular/router';
22import { Type } from '@angular/core';
23import { UrlHandlingStrategy } from '@angular/router';
24import { 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 */
32export 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 */
117export 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 */
130export 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
132export { }