1 | /**
|
2 | * @license Angular v8.0.2
|
3 | * (c) 2010-2019 Google LLC. https://angular.io/
|
4 | * License: MIT
|
5 | */
|
6 |
|
7 | (function (global, factory) {
|
8 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/common'), require('@angular/common/testing'), require('@angular/core'), require('@angular/router')) :
|
9 | typeof define === 'function' && define.amd ? define('@angular/router/testing', ['exports', '@angular/common', '@angular/common/testing', '@angular/core', '@angular/router'], factory) :
|
10 | (global = global || self, factory((global.ng = global.ng || {}, global.ng.router = global.ng.router || {}, global.ng.router.testing = {}), global.ng.common, global.ng.common.testing, global.ng.core, global.ng.router));
|
11 | }(this, function (exports, common, testing, core, router) { 'use strict';
|
12 |
|
13 | /*! *****************************************************************************
|
14 | Copyright (c) Microsoft Corporation. All rights reserved.
|
15 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
16 | this file except in compliance with the License. You may obtain a copy of the
|
17 | License at http://www.apache.org/licenses/LICENSE-2.0
|
18 |
|
19 | THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
20 | KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
21 | WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
22 | MERCHANTABLITY OR NON-INFRINGEMENT.
|
23 |
|
24 | See the Apache Version 2.0 License for specific language governing permissions
|
25 | and limitations under the License.
|
26 | ***************************************************************************** */
|
27 |
|
28 | function __decorate(decorators, target, key, desc) {
|
29 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
30 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
31 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
32 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
33 | }
|
34 |
|
35 | function __metadata(metadataKey, metadataValue) {
|
36 | if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
|
37 | }
|
38 |
|
39 | function __values(o) {
|
40 | var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
|
41 | if (m) return m.call(o);
|
42 | return {
|
43 | next: function () {
|
44 | if (o && i >= o.length) o = void 0;
|
45 | return { value: o && o[i++], done: !o };
|
46 | }
|
47 | };
|
48 | }
|
49 |
|
50 | /**
|
51 | * @license
|
52 | * Copyright Google Inc. All Rights Reserved.
|
53 | *
|
54 | * Use of this source code is governed by an MIT-style license that can be
|
55 | * found in the LICENSE file at https://angular.io/license
|
56 | */
|
57 | /**
|
58 | * @description
|
59 | *
|
60 | * Allows to simulate the loading of ng modules in tests.
|
61 | *
|
62 | * ```
|
63 | * const loader = TestBed.get(NgModuleFactoryLoader);
|
64 | *
|
65 | * @Component({template: 'lazy-loaded'})
|
66 | * class LazyLoadedComponent {}
|
67 | * @NgModule({
|
68 | * declarations: [LazyLoadedComponent],
|
69 | * imports: [RouterModule.forChild([{path: 'loaded', component: LazyLoadedComponent}])]
|
70 | * })
|
71 | *
|
72 | * class LoadedModule {}
|
73 | *
|
74 | * // sets up stubbedModules
|
75 | * loader.stubbedModules = {lazyModule: LoadedModule};
|
76 | *
|
77 | * router.resetConfig([
|
78 | * {path: 'lazy', loadChildren: 'lazyModule'},
|
79 | * ]);
|
80 | *
|
81 | * router.navigateByUrl('/lazy/loaded');
|
82 | * ```
|
83 | *
|
84 | * @publicApi
|
85 | */
|
86 | var SpyNgModuleFactoryLoader = /** @class */ (function () {
|
87 | function SpyNgModuleFactoryLoader(compiler) {
|
88 | this.compiler = compiler;
|
89 | /**
|
90 | * @docsNotRequired
|
91 | */
|
92 | this._stubbedModules = {};
|
93 | }
|
94 | Object.defineProperty(SpyNgModuleFactoryLoader.prototype, "stubbedModules", {
|
95 | /**
|
96 | * @docsNotRequired
|
97 | */
|
98 | get: function () { return this._stubbedModules; },
|
99 | /**
|
100 | * @docsNotRequired
|
101 | */
|
102 | set: function (modules) {
|
103 | var e_1, _a;
|
104 | var res = {};
|
105 | try {
|
106 | for (var _b = __values(Object.keys(modules)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
107 | var t = _c.value;
|
108 | res[t] = this.compiler.compileModuleAsync(modules[t]);
|
109 | }
|
110 | }
|
111 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
112 | finally {
|
113 | try {
|
114 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
115 | }
|
116 | finally { if (e_1) throw e_1.error; }
|
117 | }
|
118 | this._stubbedModules = res;
|
119 | },
|
120 | enumerable: true,
|
121 | configurable: true
|
122 | });
|
123 | SpyNgModuleFactoryLoader.prototype.load = function (path) {
|
124 | if (this._stubbedModules[path]) {
|
125 | return this._stubbedModules[path];
|
126 | }
|
127 | else {
|
128 | return Promise.reject(new Error("Cannot find module " + path));
|
129 | }
|
130 | };
|
131 | SpyNgModuleFactoryLoader = __decorate([
|
132 | core.Injectable(),
|
133 | __metadata("design:paramtypes", [core.Compiler])
|
134 | ], SpyNgModuleFactoryLoader);
|
135 | return SpyNgModuleFactoryLoader;
|
136 | }());
|
137 | function isUrlHandlingStrategy(opts) {
|
138 | // This property check is needed because UrlHandlingStrategy is an interface and doesn't exist at
|
139 | // runtime.
|
140 | return 'shouldProcessUrl' in opts;
|
141 | }
|
142 | /**
|
143 | * Router setup factory function used for testing.
|
144 | *
|
145 | * @publicApi
|
146 | */
|
147 | function setupTestingRouter(urlSerializer, contexts, location, loader, compiler, injector, routes, opts, urlHandlingStrategy) {
|
148 | var router$1 = new router.Router(null, urlSerializer, contexts, location, injector, loader, compiler, router.ɵflatten(routes));
|
149 | if (opts) {
|
150 | // Handle deprecated argument ordering.
|
151 | if (isUrlHandlingStrategy(opts)) {
|
152 | router$1.urlHandlingStrategy = opts;
|
153 | }
|
154 | else {
|
155 | // Handle ExtraOptions
|
156 | if (opts.malformedUriErrorHandler) {
|
157 | router$1.malformedUriErrorHandler = opts.malformedUriErrorHandler;
|
158 | }
|
159 | if (opts.paramsInheritanceStrategy) {
|
160 | router$1.paramsInheritanceStrategy = opts.paramsInheritanceStrategy;
|
161 | }
|
162 | }
|
163 | }
|
164 | if (urlHandlingStrategy) {
|
165 | router$1.urlHandlingStrategy = urlHandlingStrategy;
|
166 | }
|
167 | return router$1;
|
168 | }
|
169 | /**
|
170 | * @description
|
171 | *
|
172 | * Sets up the router to be used for testing.
|
173 | *
|
174 | * The modules sets up the router to be used for testing.
|
175 | * It provides spy implementations of `Location`, `LocationStrategy`, and {@link
|
176 | * NgModuleFactoryLoader}.
|
177 | *
|
178 | * @usageNotes
|
179 | * ### Example
|
180 | *
|
181 | * ```
|
182 | * beforeEach(() => {
|
183 | * TestBed.configureTestModule({
|
184 | * imports: [
|
185 | * RouterTestingModule.withRoutes(
|
186 | * [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}]
|
187 | * )
|
188 | * ]
|
189 | * });
|
190 | * });
|
191 | * ```
|
192 | *
|
193 | * @publicApi
|
194 | */
|
195 | var RouterTestingModule = /** @class */ (function () {
|
196 | function RouterTestingModule() {
|
197 | }
|
198 | RouterTestingModule_1 = RouterTestingModule;
|
199 | RouterTestingModule.withRoutes = function (routes, config) {
|
200 | return {
|
201 | ngModule: RouterTestingModule_1,
|
202 | providers: [
|
203 | router.provideRoutes(routes),
|
204 | { provide: router.ROUTER_CONFIGURATION, useValue: config ? config : {} },
|
205 | ]
|
206 | };
|
207 | };
|
208 | var RouterTestingModule_1;
|
209 | RouterTestingModule = RouterTestingModule_1 = __decorate([
|
210 | core.NgModule({
|
211 | exports: [router.RouterModule],
|
212 | providers: [
|
213 | router.ɵROUTER_PROVIDERS, { provide: common.Location, useClass: testing.SpyLocation },
|
214 | { provide: common.LocationStrategy, useClass: testing.MockLocationStrategy },
|
215 | { provide: core.NgModuleFactoryLoader, useClass: SpyNgModuleFactoryLoader }, {
|
216 | provide: router.Router,
|
217 | useFactory: setupTestingRouter,
|
218 | deps: [
|
219 | router.UrlSerializer, router.ChildrenOutletContexts, common.Location, core.NgModuleFactoryLoader, core.Compiler, core.Injector,
|
220 | router.ROUTES, router.ROUTER_CONFIGURATION, [router.UrlHandlingStrategy, new core.Optional()]
|
221 | ]
|
222 | },
|
223 | { provide: router.PreloadingStrategy, useExisting: router.NoPreloading }, router.provideRoutes([])
|
224 | ]
|
225 | })
|
226 | ], RouterTestingModule);
|
227 | return RouterTestingModule;
|
228 | }());
|
229 |
|
230 | /**
|
231 | * @license
|
232 | * Copyright Google Inc. All Rights Reserved.
|
233 | *
|
234 | * Use of this source code is governed by an MIT-style license that can be
|
235 | * found in the LICENSE file at https://angular.io/license
|
236 | */
|
237 |
|
238 | /**
|
239 | * @license
|
240 | * Copyright Google Inc. All Rights Reserved.
|
241 | *
|
242 | * Use of this source code is governed by an MIT-style license that can be
|
243 | * found in the LICENSE file at https://angular.io/license
|
244 | */
|
245 | // This file only reexports content of the `src` folder. Keep it that way.
|
246 |
|
247 | /**
|
248 | * @license
|
249 | * Copyright Google Inc. All Rights Reserved.
|
250 | *
|
251 | * Use of this source code is governed by an MIT-style license that can be
|
252 | * found in the LICENSE file at https://angular.io/license
|
253 | */
|
254 |
|
255 | /**
|
256 | * Generated bundle index. Do not edit.
|
257 | */
|
258 |
|
259 | exports.SpyNgModuleFactoryLoader = SpyNgModuleFactoryLoader;
|
260 | exports.setupTestingRouter = setupTestingRouter;
|
261 | exports.RouterTestingModule = RouterTestingModule;
|
262 |
|
263 | Object.defineProperty(exports, '__esModule', { value: true });
|
264 |
|
265 | }));
|
266 | //# sourceMappingURL=router-testing.umd.js.map
|