UNPKG

18.5 kBJavaScriptView Raw
1/**
2 * @license Angular v9.0.2
3 * (c) 2010-2020 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 /* global Reflect, Promise */
28
29 var extendStatics = function(d, b) {
30 extendStatics = Object.setPrototypeOf ||
31 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
32 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
33 return extendStatics(d, b);
34 };
35
36 function __extends(d, b) {
37 extendStatics(d, b);
38 function __() { this.constructor = d; }
39 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
40 }
41
42 var __assign = function() {
43 __assign = Object.assign || function __assign(t) {
44 for (var s, i = 1, n = arguments.length; i < n; i++) {
45 s = arguments[i];
46 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
47 }
48 return t;
49 };
50 return __assign.apply(this, arguments);
51 };
52
53 function __rest(s, e) {
54 var t = {};
55 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
56 t[p] = s[p];
57 if (s != null && typeof Object.getOwnPropertySymbols === "function")
58 for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
59 if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
60 t[p[i]] = s[p[i]];
61 }
62 return t;
63 }
64
65 function __decorate(decorators, target, key, desc) {
66 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
67 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
68 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;
69 return c > 3 && r && Object.defineProperty(target, key, r), r;
70 }
71
72 function __param(paramIndex, decorator) {
73 return function (target, key) { decorator(target, key, paramIndex); }
74 }
75
76 function __metadata(metadataKey, metadataValue) {
77 if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
78 }
79
80 function __awaiter(thisArg, _arguments, P, generator) {
81 return new (P || (P = Promise))(function (resolve, reject) {
82 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
83 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
84 function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
85 step((generator = generator.apply(thisArg, _arguments || [])).next());
86 });
87 }
88
89 function __generator(thisArg, body) {
90 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
91 return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
92 function verb(n) { return function (v) { return step([n, v]); }; }
93 function step(op) {
94 if (f) throw new TypeError("Generator is already executing.");
95 while (_) try {
96 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
97 if (y = 0, t) op = [op[0] & 2, t.value];
98 switch (op[0]) {
99 case 0: case 1: t = op; break;
100 case 4: _.label++; return { value: op[1], done: false };
101 case 5: _.label++; y = op[1]; op = [0]; continue;
102 case 7: op = _.ops.pop(); _.trys.pop(); continue;
103 default:
104 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
105 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
106 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
107 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
108 if (t[2]) _.ops.pop();
109 _.trys.pop(); continue;
110 }
111 op = body.call(thisArg, _);
112 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
113 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
114 }
115 }
116
117 function __exportStar(m, exports) {
118 for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
119 }
120
121 function __values(o) {
122 var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
123 if (m) return m.call(o);
124 return {
125 next: function () {
126 if (o && i >= o.length) o = void 0;
127 return { value: o && o[i++], done: !o };
128 }
129 };
130 }
131
132 function __read(o, n) {
133 var m = typeof Symbol === "function" && o[Symbol.iterator];
134 if (!m) return o;
135 var i = m.call(o), r, ar = [], e;
136 try {
137 while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
138 }
139 catch (error) { e = { error: error }; }
140 finally {
141 try {
142 if (r && !r.done && (m = i["return"])) m.call(i);
143 }
144 finally { if (e) throw e.error; }
145 }
146 return ar;
147 }
148
149 function __spread() {
150 for (var ar = [], i = 0; i < arguments.length; i++)
151 ar = ar.concat(__read(arguments[i]));
152 return ar;
153 }
154
155 function __spreadArrays() {
156 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
157 for (var r = Array(s), k = 0, i = 0; i < il; i++)
158 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
159 r[k] = a[j];
160 return r;
161 };
162
163 function __await(v) {
164 return this instanceof __await ? (this.v = v, this) : new __await(v);
165 }
166
167 function __asyncGenerator(thisArg, _arguments, generator) {
168 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
169 var g = generator.apply(thisArg, _arguments || []), i, q = [];
170 return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
171 function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
172 function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
173 function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
174 function fulfill(value) { resume("next", value); }
175 function reject(value) { resume("throw", value); }
176 function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
177 }
178
179 function __asyncDelegator(o) {
180 var i, p;
181 return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
182 function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
183 }
184
185 function __asyncValues(o) {
186 if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
187 var m = o[Symbol.asyncIterator], i;
188 return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
189 function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
190 function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
191 }
192
193 function __makeTemplateObject(cooked, raw) {
194 if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
195 return cooked;
196 };
197
198 function __importStar(mod) {
199 if (mod && mod.__esModule) return mod;
200 var result = {};
201 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
202 result.default = mod;
203 return result;
204 }
205
206 function __importDefault(mod) {
207 return (mod && mod.__esModule) ? mod : { default: mod };
208 }
209
210 /**
211 * @license
212 * Copyright Google Inc. All Rights Reserved.
213 *
214 * Use of this source code is governed by an MIT-style license that can be
215 * found in the LICENSE file at https://angular.io/license
216 */
217 /**
218 * @description
219 *
220 * Allows to simulate the loading of ng modules in tests.
221 *
222 * ```
223 * const loader = TestBed.inject(NgModuleFactoryLoader);
224 *
225 * @Component({template: 'lazy-loaded'})
226 * class LazyLoadedComponent {}
227 * @NgModule({
228 * declarations: [LazyLoadedComponent],
229 * imports: [RouterModule.forChild([{path: 'loaded', component: LazyLoadedComponent}])]
230 * })
231 *
232 * class LoadedModule {}
233 *
234 * // sets up stubbedModules
235 * loader.stubbedModules = {lazyModule: LoadedModule};
236 *
237 * router.resetConfig([
238 * {path: 'lazy', loadChildren: 'lazyModule'},
239 * ]);
240 *
241 * router.navigateByUrl('/lazy/loaded');
242 * ```
243 *
244 * @publicApi
245 */
246 var SpyNgModuleFactoryLoader = /** @class */ (function () {
247 function SpyNgModuleFactoryLoader(compiler) {
248 this.compiler = compiler;
249 /**
250 * @docsNotRequired
251 */
252 this._stubbedModules = {};
253 }
254 Object.defineProperty(SpyNgModuleFactoryLoader.prototype, "stubbedModules", {
255 /**
256 * @docsNotRequired
257 */
258 get: function () { return this._stubbedModules; },
259 /**
260 * @docsNotRequired
261 */
262 set: function (modules) {
263 var e_1, _a;
264 var res = {};
265 try {
266 for (var _b = __values(Object.keys(modules)), _c = _b.next(); !_c.done; _c = _b.next()) {
267 var t = _c.value;
268 res[t] = this.compiler.compileModuleAsync(modules[t]);
269 }
270 }
271 catch (e_1_1) { e_1 = { error: e_1_1 }; }
272 finally {
273 try {
274 if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
275 }
276 finally { if (e_1) throw e_1.error; }
277 }
278 this._stubbedModules = res;
279 },
280 enumerable: true,
281 configurable: true
282 });
283 SpyNgModuleFactoryLoader.prototype.load = function (path) {
284 if (this._stubbedModules[path]) {
285 return this._stubbedModules[path];
286 }
287 else {
288 return Promise.reject(new Error("Cannot find module " + path));
289 }
290 };
291 SpyNgModuleFactoryLoader = __decorate([
292 core.Injectable(),
293 __metadata("design:paramtypes", [core.Compiler])
294 ], SpyNgModuleFactoryLoader);
295 return SpyNgModuleFactoryLoader;
296 }());
297 function isUrlHandlingStrategy(opts) {
298 // This property check is needed because UrlHandlingStrategy is an interface and doesn't exist at
299 // runtime.
300 return 'shouldProcessUrl' in opts;
301 }
302 /**
303 * Router setup factory function used for testing.
304 *
305 * @publicApi
306 */
307 function setupTestingRouter(urlSerializer, contexts, location, loader, compiler, injector, routes, opts, urlHandlingStrategy) {
308 var router$1 = new router.Router(null, urlSerializer, contexts, location, injector, loader, compiler, router.ɵflatten(routes));
309 if (opts) {
310 // Handle deprecated argument ordering.
311 if (isUrlHandlingStrategy(opts)) {
312 router$1.urlHandlingStrategy = opts;
313 }
314 else {
315 // Handle ExtraOptions
316 if (opts.malformedUriErrorHandler) {
317 router$1.malformedUriErrorHandler = opts.malformedUriErrorHandler;
318 }
319 if (opts.paramsInheritanceStrategy) {
320 router$1.paramsInheritanceStrategy = opts.paramsInheritanceStrategy;
321 }
322 }
323 }
324 if (urlHandlingStrategy) {
325 router$1.urlHandlingStrategy = urlHandlingStrategy;
326 }
327 return router$1;
328 }
329 /**
330 * @description
331 *
332 * Sets up the router to be used for testing.
333 *
334 * The modules sets up the router to be used for testing.
335 * It provides spy implementations of `Location`, `LocationStrategy`, and {@link
336 * NgModuleFactoryLoader}.
337 *
338 * @usageNotes
339 * ### Example
340 *
341 * ```
342 * beforeEach(() => {
343 * TestBed.configureTestModule({
344 * imports: [
345 * RouterTestingModule.withRoutes(
346 * [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}]
347 * )
348 * ]
349 * });
350 * });
351 * ```
352 *
353 * @publicApi
354 */
355 var RouterTestingModule = /** @class */ (function () {
356 function RouterTestingModule() {
357 }
358 RouterTestingModule_1 = RouterTestingModule;
359 RouterTestingModule.withRoutes = function (routes, config) {
360 return {
361 ngModule: RouterTestingModule_1,
362 providers: [
363 router.provideRoutes(routes),
364 { provide: router.ROUTER_CONFIGURATION, useValue: config ? config : {} },
365 ]
366 };
367 };
368 var RouterTestingModule_1;
369 RouterTestingModule = RouterTestingModule_1 = __decorate([
370 core.NgModule({
371 exports: [router.RouterModule],
372 providers: [
373 router.ɵROUTER_PROVIDERS, { provide: common.Location, useClass: testing.SpyLocation },
374 { provide: common.LocationStrategy, useClass: testing.MockLocationStrategy },
375 { provide: core.NgModuleFactoryLoader, useClass: SpyNgModuleFactoryLoader }, {
376 provide: router.Router,
377 useFactory: setupTestingRouter,
378 deps: [
379 router.UrlSerializer, router.ChildrenOutletContexts, common.Location, core.NgModuleFactoryLoader, core.Compiler, core.Injector,
380 router.ROUTES, router.ROUTER_CONFIGURATION, [router.UrlHandlingStrategy, new core.Optional()]
381 ]
382 },
383 { provide: router.PreloadingStrategy, useExisting: router.NoPreloading }, router.provideRoutes([])
384 ]
385 })
386 ], RouterTestingModule);
387 return RouterTestingModule;
388 }());
389
390 /**
391 * @license
392 * Copyright Google Inc. All Rights Reserved.
393 *
394 * Use of this source code is governed by an MIT-style license that can be
395 * found in the LICENSE file at https://angular.io/license
396 */
397
398 /**
399 * @license
400 * Copyright Google Inc. All Rights Reserved.
401 *
402 * Use of this source code is governed by an MIT-style license that can be
403 * found in the LICENSE file at https://angular.io/license
404 */
405 // This file only reexports content of the `src` folder. Keep it that way.
406
407 /**
408 * @license
409 * Copyright Google Inc. All Rights Reserved.
410 *
411 * Use of this source code is governed by an MIT-style license that can be
412 * found in the LICENSE file at https://angular.io/license
413 */
414
415 /**
416 * Generated bundle index. Do not edit.
417 */
418
419 exports.RouterTestingModule = RouterTestingModule;
420 exports.SpyNgModuleFactoryLoader = SpyNgModuleFactoryLoader;
421 exports.setupTestingRouter = setupTestingRouter;
422
423 Object.defineProperty(exports, '__esModule', { value: true });
424
425})));
426//# sourceMappingURL=router-testing.umd.js.map