router-testing.umd.js 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /**
  2. * @license Angular v6.0.9
  3. * (c) 2010-2018 Google, Inc. 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. (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 __values(o) {
  24. var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
  25. if (m) return m.call(o);
  26. return {
  27. next: function () {
  28. if (o && i >= o.length) o = void 0;
  29. return { value: o && o[i++], done: !o };
  30. }
  31. };
  32. }
  33. /**
  34. * @license
  35. * Copyright Google Inc. All Rights Reserved.
  36. *
  37. * Use of this source code is governed by an MIT-style license that can be
  38. * found in the LICENSE file at https://angular.io/license
  39. */
  40. /**
  41. * @description
  42. *
  43. * Allows to simulate the loading of ng modules in tests.
  44. *
  45. * ```
  46. * const loader = TestBed.get(NgModuleFactoryLoader);
  47. *
  48. * @Component({template: 'lazy-loaded'})
  49. * class LazyLoadedComponent {}
  50. * @NgModule({
  51. * declarations: [LazyLoadedComponent],
  52. * imports: [RouterModule.forChild([{path: 'loaded', component: LazyLoadedComponent}])]
  53. * })
  54. *
  55. * class LoadedModule {}
  56. *
  57. * // sets up stubbedModules
  58. * loader.stubbedModules = {lazyModule: LoadedModule};
  59. *
  60. * router.resetConfig([
  61. * {path: 'lazy', loadChildren: 'lazyModule'},
  62. * ]);
  63. *
  64. * router.navigateByUrl('/lazy/loaded');
  65. * ```
  66. *
  67. *
  68. */
  69. var SpyNgModuleFactoryLoader = /** @class */ (function () {
  70. function SpyNgModuleFactoryLoader(compiler) {
  71. this.compiler = compiler;
  72. /**
  73. * @docsNotRequired
  74. */
  75. this._stubbedModules = {};
  76. }
  77. Object.defineProperty(SpyNgModuleFactoryLoader.prototype, "stubbedModules", {
  78. /**
  79. * @docsNotRequired
  80. */
  81. get: function () { return this._stubbedModules; },
  82. /**
  83. * @docsNotRequired
  84. */
  85. set: function (modules) {
  86. var res = {};
  87. try {
  88. for (var _a = __values(Object.keys(modules)), _b = _a.next(); !_b.done; _b = _a.next()) {
  89. var t = _b.value;
  90. res[t] = this.compiler.compileModuleAsync(modules[t]);
  91. }
  92. }
  93. catch (e_1_1) { e_1 = { error: e_1_1 }; }
  94. finally {
  95. try {
  96. if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
  97. }
  98. finally { if (e_1) throw e_1.error; }
  99. }
  100. this._stubbedModules = res;
  101. var e_1, _c;
  102. },
  103. enumerable: true,
  104. configurable: true
  105. });
  106. SpyNgModuleFactoryLoader.prototype.load = function (path) {
  107. if (this._stubbedModules[path]) {
  108. return this._stubbedModules[path];
  109. }
  110. else {
  111. return Promise.reject(new Error("Cannot find module " + path));
  112. }
  113. };
  114. SpyNgModuleFactoryLoader.decorators = [
  115. { type: core.Injectable }
  116. ];
  117. /** @nocollapse */
  118. SpyNgModuleFactoryLoader.ctorParameters = function () { return [
  119. { type: core.Compiler }
  120. ]; };
  121. return SpyNgModuleFactoryLoader;
  122. }());
  123. function isUrlHandlingStrategy(opts) {
  124. // This property check is needed because UrlHandlingStrategy is an interface and doesn't exist at
  125. // runtime.
  126. return 'shouldProcessUrl' in opts;
  127. }
  128. /**
  129. * Router setup factory function used for testing.
  130. *
  131. *
  132. */
  133. function setupTestingRouter(urlSerializer, contexts, location, loader, compiler, injector, routes, opts, urlHandlingStrategy) {
  134. var router$$1 = new router.Router(null, urlSerializer, contexts, location, injector, loader, compiler, router.ɵflatten(routes));
  135. if (opts) {
  136. // Handle deprecated argument ordering.
  137. if (isUrlHandlingStrategy(opts)) {
  138. router$$1.urlHandlingStrategy = opts;
  139. }
  140. else {
  141. // Handle ExtraOptions
  142. if (opts.malformedUriErrorHandler) {
  143. router$$1.malformedUriErrorHandler = opts.malformedUriErrorHandler;
  144. }
  145. if (opts.paramsInheritanceStrategy) {
  146. router$$1.paramsInheritanceStrategy = opts.paramsInheritanceStrategy;
  147. }
  148. }
  149. }
  150. if (urlHandlingStrategy) {
  151. router$$1.urlHandlingStrategy = urlHandlingStrategy;
  152. }
  153. return router$$1;
  154. }
  155. /**
  156. * @description
  157. *
  158. * Sets up the router to be used for testing.
  159. *
  160. * The modules sets up the router to be used for testing.
  161. * It provides spy implementations of `Location`, `LocationStrategy`, and {@link
  162. * NgModuleFactoryLoader}.
  163. *
  164. * ### Example
  165. *
  166. * ```
  167. * beforeEach(() => {
  168. * TestBed.configureTestModule({
  169. * imports: [
  170. * RouterTestingModule.withRoutes(
  171. * [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}]
  172. * )
  173. * ]
  174. * });
  175. * });
  176. * ```
  177. *
  178. *
  179. */
  180. var RouterTestingModule = /** @class */ (function () {
  181. function RouterTestingModule() {
  182. }
  183. RouterTestingModule.withRoutes = function (routes, config) {
  184. return {
  185. ngModule: RouterTestingModule,
  186. providers: [
  187. router.provideRoutes(routes),
  188. { provide: router.ROUTER_CONFIGURATION, useValue: config ? config : {} },
  189. ]
  190. };
  191. };
  192. RouterTestingModule.decorators = [
  193. { type: core.NgModule, args: [{
  194. exports: [router.RouterModule],
  195. providers: [
  196. router.ɵROUTER_PROVIDERS, { provide: common.Location, useClass: testing.SpyLocation },
  197. { provide: common.LocationStrategy, useClass: testing.MockLocationStrategy },
  198. { provide: core.NgModuleFactoryLoader, useClass: SpyNgModuleFactoryLoader }, {
  199. provide: router.Router,
  200. useFactory: setupTestingRouter,
  201. deps: [
  202. router.UrlSerializer, router.ChildrenOutletContexts, common.Location, core.NgModuleFactoryLoader, core.Compiler, core.Injector,
  203. router.ROUTES, router.ROUTER_CONFIGURATION, [router.UrlHandlingStrategy, new core.Optional()]
  204. ]
  205. },
  206. { provide: router.PreloadingStrategy, useExisting: router.NoPreloading }, router.provideRoutes([])
  207. ]
  208. },] }
  209. ];
  210. return RouterTestingModule;
  211. }());
  212. /**
  213. * @license
  214. * Copyright Google Inc. All Rights Reserved.
  215. *
  216. * Use of this source code is governed by an MIT-style license that can be
  217. * found in the LICENSE file at https://angular.io/license
  218. */
  219. /**
  220. * @license
  221. * Copyright Google Inc. All Rights Reserved.
  222. *
  223. * Use of this source code is governed by an MIT-style license that can be
  224. * found in the LICENSE file at https://angular.io/license
  225. */
  226. // This file only reexports content of the `src` folder. Keep it that way.
  227. /**
  228. * @license
  229. * Copyright Google Inc. All Rights Reserved.
  230. *
  231. * Use of this source code is governed by an MIT-style license that can be
  232. * found in the LICENSE file at https://angular.io/license
  233. */
  234. /**
  235. * Generated bundle index. Do not edit.
  236. */
  237. exports.SpyNgModuleFactoryLoader = SpyNgModuleFactoryLoader;
  238. exports.setupTestingRouter = setupTestingRouter;
  239. exports.RouterTestingModule = RouterTestingModule;
  240. Object.defineProperty(exports, '__esModule', { value: true });
  241. })));
  242. //# sourceMappingURL=router-testing.umd.js.map