router-testing.umd.js 10 KB

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