source: trip-planner-front/node_modules/@angular/router/fesm2015/testing.js@ 59329aa

Last change on this file since 59329aa was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 6.0 KB
Line 
1/**
2 * @license Angular v12.2.9
3 * (c) 2010-2021 Google LLC. https://angular.io/
4 * License: MIT
5 */
6
7import { Location, LocationStrategy } from '@angular/common';
8import { SpyLocation, MockLocationStrategy } from '@angular/common/testing';
9import { Injectable, Compiler, NgModule, NgModuleFactoryLoader, Injector, Optional } from '@angular/core';
10import { Router, ɵflatten, ɵassignExtraOptionsToRouter, provideRoutes, ROUTER_CONFIGURATION, RouterModule, ɵROUTER_PROVIDERS, UrlSerializer, ChildrenOutletContexts, ROUTES, UrlHandlingStrategy, RouteReuseStrategy, PreloadingStrategy, NoPreloading } from '@angular/router';
11
12/**
13 * @license
14 * Copyright Google LLC All Rights Reserved.
15 *
16 * Use of this source code is governed by an MIT-style license that can be
17 * found in the LICENSE file at https://angular.io/license
18 */
19/**
20 * @description
21 *
22 * Allows to simulate the loading of ng modules in tests.
23 *
24 * ```
25 * const loader = TestBed.inject(NgModuleFactoryLoader);
26 *
27 * @Component({template: 'lazy-loaded'})
28 * class LazyLoadedComponent {}
29 * @NgModule({
30 * declarations: [LazyLoadedComponent],
31 * imports: [RouterModule.forChild([{path: 'loaded', component: LazyLoadedComponent}])]
32 * })
33 *
34 * class LoadedModule {}
35 *
36 * // sets up stubbedModules
37 * loader.stubbedModules = {lazyModule: LoadedModule};
38 *
39 * router.resetConfig([
40 * {path: 'lazy', loadChildren: 'lazyModule'},
41 * ]);
42 *
43 * router.navigateByUrl('/lazy/loaded');
44 * ```
45 *
46 * @publicApi
47 */
48class SpyNgModuleFactoryLoader {
49 constructor(compiler) {
50 this.compiler = compiler;
51 /**
52 * @docsNotRequired
53 */
54 this._stubbedModules = {};
55 }
56 /**
57 * @docsNotRequired
58 */
59 set stubbedModules(modules) {
60 const res = {};
61 for (const t of Object.keys(modules)) {
62 res[t] = this.compiler.compileModuleAsync(modules[t]);
63 }
64 this._stubbedModules = res;
65 }
66 /**
67 * @docsNotRequired
68 */
69 get stubbedModules() {
70 return this._stubbedModules;
71 }
72 load(path) {
73 if (this._stubbedModules[path]) {
74 return this._stubbedModules[path];
75 }
76 else {
77 return Promise.reject(new Error(`Cannot find module ${path}`));
78 }
79 }
80}
81SpyNgModuleFactoryLoader.decorators = [
82 { type: Injectable }
83];
84SpyNgModuleFactoryLoader.ctorParameters = () => [
85 { type: Compiler }
86];
87function isUrlHandlingStrategy(opts) {
88 // This property check is needed because UrlHandlingStrategy is an interface and doesn't exist at
89 // runtime.
90 return 'shouldProcessUrl' in opts;
91}
92/**
93 * Router setup factory function used for testing.
94 *
95 * @publicApi
96 */
97function setupTestingRouter(urlSerializer, contexts, location, loader, compiler, injector, routes, opts, urlHandlingStrategy, routeReuseStrategy) {
98 const router = new Router(null, urlSerializer, contexts, location, injector, loader, compiler, ɵflatten(routes));
99 if (opts) {
100 // Handle deprecated argument ordering.
101 if (isUrlHandlingStrategy(opts)) {
102 router.urlHandlingStrategy = opts;
103 }
104 else {
105 // Handle ExtraOptions
106 ɵassignExtraOptionsToRouter(opts, router);
107 }
108 }
109 if (urlHandlingStrategy) {
110 router.urlHandlingStrategy = urlHandlingStrategy;
111 }
112 if (routeReuseStrategy) {
113 router.routeReuseStrategy = routeReuseStrategy;
114 }
115 return router;
116}
117/**
118 * @description
119 *
120 * Sets up the router to be used for testing.
121 *
122 * The modules sets up the router to be used for testing.
123 * It provides spy implementations of `Location`, `LocationStrategy`, and {@link
124 * NgModuleFactoryLoader}.
125 *
126 * @usageNotes
127 * ### Example
128 *
129 * ```
130 * beforeEach(() => {
131 * TestBed.configureTestingModule({
132 * imports: [
133 * RouterTestingModule.withRoutes(
134 * [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}]
135 * )
136 * ]
137 * });
138 * });
139 * ```
140 *
141 * @publicApi
142 */
143class RouterTestingModule {
144 static withRoutes(routes, config) {
145 return {
146 ngModule: RouterTestingModule,
147 providers: [
148 provideRoutes(routes),
149 { provide: ROUTER_CONFIGURATION, useValue: config ? config : {} },
150 ]
151 };
152 }
153}
154RouterTestingModule.decorators = [
155 { type: NgModule, args: [{
156 exports: [RouterModule],
157 providers: [
158 ɵROUTER_PROVIDERS, { provide: Location, useClass: SpyLocation },
159 { provide: LocationStrategy, useClass: MockLocationStrategy },
160 { provide: NgModuleFactoryLoader, useClass: SpyNgModuleFactoryLoader }, {
161 provide: Router,
162 useFactory: setupTestingRouter,
163 deps: [
164 UrlSerializer, ChildrenOutletContexts, Location, NgModuleFactoryLoader, Compiler, Injector,
165 ROUTES, ROUTER_CONFIGURATION, [UrlHandlingStrategy, new Optional()],
166 [RouteReuseStrategy, new Optional()]
167 ]
168 },
169 { provide: PreloadingStrategy, useExisting: NoPreloading }, provideRoutes([])
170 ]
171 },] }
172];
173
174/**
175 * @license
176 * Copyright Google LLC All Rights Reserved.
177 *
178 * Use of this source code is governed by an MIT-style license that can be
179 * found in the LICENSE file at https://angular.io/license
180 */
181
182/**
183 * @license
184 * Copyright Google LLC All Rights Reserved.
185 *
186 * Use of this source code is governed by an MIT-style license that can be
187 * found in the LICENSE file at https://angular.io/license
188 */
189// This file only reexports content of the `src` folder. Keep it that way.
190
191/**
192 * @license
193 * Copyright Google LLC All Rights Reserved.
194 *
195 * Use of this source code is governed by an MIT-style license that can be
196 * found in the LICENSE file at https://angular.io/license
197 */
198
199/**
200 * Generated bundle index. Do not edit.
201 */
202
203export { RouterTestingModule, SpyNgModuleFactoryLoader, setupTestingRouter };
204//# sourceMappingURL=testing.js.map
Note: See TracBrowser for help on using the repository browser.