blob: c567c449db50b4b4081428b4564c6d223d83f6ff [file] [log] [blame]
{"version":3,"file":"testing.js","sources":["../../../../../../packages/router/testing/src/router_testing_module.ts","../../../../../../packages/router/testing/src/testing.ts","../../../../../../packages/router/testing/public_api.ts","../../../../../../packages/router/testing/index.ts","../../../../../../packages/router/testing/testing.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {Location, LocationStrategy} from '@angular/common';\nimport {MockLocationStrategy, SpyLocation} from '@angular/common/testing';\nimport {Compiler, Injectable, Injector, ModuleWithProviders, NgModule, NgModuleFactory, NgModuleFactoryLoader, Optional} from '@angular/core';\nimport {ChildrenOutletContexts, ExtraOptions, NoPreloading, PreloadingStrategy, ROUTER_CONFIGURATION, ROUTES, Route, Router, RouterModule, Routes, UrlHandlingStrategy, UrlSerializer, provideRoutes, ɵROUTER_PROVIDERS as ROUTER_PROVIDERS, ɵflatten as flatten} from '@angular/router';\n\n\n\n/**\n * @description\n *\n * Allows to simulate the loading of ng modules in tests.\n *\n * ```\n * const loader = TestBed.get(NgModuleFactoryLoader);\n *\n * @Component({template: 'lazy-loaded'})\n * class LazyLoadedComponent {}\n * @NgModule({\n * declarations: [LazyLoadedComponent],\n * imports: [RouterModule.forChild([{path: 'loaded', component: LazyLoadedComponent}])]\n * })\n *\n * class LoadedModule {}\n *\n * // sets up stubbedModules\n * loader.stubbedModules = {lazyModule: LoadedModule};\n *\n * router.resetConfig([\n * {path: 'lazy', loadChildren: 'lazyModule'},\n * ]);\n *\n * router.navigateByUrl('/lazy/loaded');\n * ```\n *\n * @publicApi\n */\n@Injectable()\nexport class SpyNgModuleFactoryLoader implements NgModuleFactoryLoader {\n /**\n * @docsNotRequired\n */\n private _stubbedModules: {[path: string]: Promise<NgModuleFactory<any>>} = {};\n\n /**\n * @docsNotRequired\n */\n set stubbedModules(modules: {[path: string]: any}) {\n const res: {[path: string]: any} = {};\n for (const t of Object.keys(modules)) {\n res[t] = this.compiler.compileModuleAsync(modules[t]);\n }\n this._stubbedModules = res;\n }\n\n /**\n * @docsNotRequired\n */\n get stubbedModules(): {[path: string]: any} { return this._stubbedModules; }\n\n constructor(private compiler: Compiler) {}\n\n load(path: string): Promise<NgModuleFactory<any>> {\n if (this._stubbedModules[path]) {\n return this._stubbedModules[path];\n } else {\n return <any>Promise.reject(new Error(`Cannot find module ${path}`));\n }\n }\n}\n\nfunction isUrlHandlingStrategy(opts: ExtraOptions | UrlHandlingStrategy):\n opts is UrlHandlingStrategy {\n // This property check is needed because UrlHandlingStrategy is an interface and doesn't exist at\n // runtime.\n return 'shouldProcessUrl' in opts;\n}\n\n/**\n * Router setup factory function used for testing.\n *\n * @publicApi\n */\nexport function setupTestingRouter(\n urlSerializer: UrlSerializer, contexts: ChildrenOutletContexts, location: Location,\n loader: NgModuleFactoryLoader, compiler: Compiler, injector: Injector, routes: Route[][],\n opts?: ExtraOptions, urlHandlingStrategy?: UrlHandlingStrategy): Router;\n\n/**\n * Router setup factory function used for testing.\n *\n * @deprecated As of v5.2. The 2nd-to-last argument should be `ExtraOptions`, not\n * `UrlHandlingStrategy`\n * @publicApi\n */\nexport function setupTestingRouter(\n urlSerializer: UrlSerializer, contexts: ChildrenOutletContexts, location: Location,\n loader: NgModuleFactoryLoader, compiler: Compiler, injector: Injector, routes: Route[][],\n urlHandlingStrategy?: UrlHandlingStrategy): Router;\n\n/**\n * Router setup factory function used for testing.\n *\n * @publicApi\n */\nexport function setupTestingRouter(\n urlSerializer: UrlSerializer, contexts: ChildrenOutletContexts, location: Location,\n loader: NgModuleFactoryLoader, compiler: Compiler, injector: Injector, routes: Route[][],\n opts?: ExtraOptions | UrlHandlingStrategy, urlHandlingStrategy?: UrlHandlingStrategy) {\n const router = new Router(\n null !, urlSerializer, contexts, location, injector, loader, compiler, flatten(routes));\n if (opts) {\n // Handle deprecated argument ordering.\n if (isUrlHandlingStrategy(opts)) {\n router.urlHandlingStrategy = opts;\n } else {\n // Handle ExtraOptions\n\n if (opts.malformedUriErrorHandler) {\n router.malformedUriErrorHandler = opts.malformedUriErrorHandler;\n }\n\n if (opts.paramsInheritanceStrategy) {\n router.paramsInheritanceStrategy = opts.paramsInheritanceStrategy;\n }\n }\n }\n\n if (urlHandlingStrategy) {\n router.urlHandlingStrategy = urlHandlingStrategy;\n }\n return router;\n}\n\n/**\n * @description\n *\n * Sets up the router to be used for testing.\n *\n * The modules sets up the router to be used for testing.\n * It provides spy implementations of `Location`, `LocationStrategy`, and {@link\n * NgModuleFactoryLoader}.\n *\n * @usageNotes\n * ### Example\n *\n * ```\n * beforeEach(() => {\n * TestBed.configureTestModule({\n * imports: [\n * RouterTestingModule.withRoutes(\n * [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}]\n * )\n * ]\n * });\n * });\n * ```\n *\n * @publicApi\n */\n@NgModule({\n exports: [RouterModule],\n providers: [\n ROUTER_PROVIDERS, {provide: Location, useClass: SpyLocation},\n {provide: LocationStrategy, useClass: MockLocationStrategy},\n {provide: NgModuleFactoryLoader, useClass: SpyNgModuleFactoryLoader}, {\n provide: Router,\n useFactory: setupTestingRouter,\n deps: [\n UrlSerializer, ChildrenOutletContexts, Location, NgModuleFactoryLoader, Compiler, Injector,\n ROUTES, ROUTER_CONFIGURATION, [UrlHandlingStrategy, new Optional()]\n ]\n },\n {provide: PreloadingStrategy, useExisting: NoPreloading}, provideRoutes([])\n ]\n})\nexport class RouterTestingModule {\n static withRoutes(routes: Routes, config?: ExtraOptions):\n ModuleWithProviders<RouterTestingModule> {\n return {\n ngModule: RouterTestingModule,\n providers: [\n provideRoutes(routes),\n {provide: ROUTER_CONFIGURATION, useValue: config ? config : {}},\n ]\n };\n }\n}\n","/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n/**\n * @module\n * @description\n * Entry point for all public APIs of the router/testing package.\n */\nexport * from './router_testing_module';\n","/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n/**\n * @module\n * @description\n * Entry point for all public APIs of this package.\n */\nexport * from './src/testing';\n\n// This file only reexports content of the `src` folder. Keep it that way.\n","/**\n * @license\n * Copyright Google Inc. All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\n// This file is not used to build this module. It is only used during editing\n// by the TypeScript language service and during build for verification. `ngc`\n// replaces this file with production index.ts when it rewrites private symbol\n// names.\n\nexport * from './public_api';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":["tslib_1.__values","flatten","ROUTER_PROVIDERS"],"mappings":";;;;;;;;;;;;AAAA;;;;;;;AAeA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA;IAsBE,kCAAoB,QAAkB;QAAlB,aAAQ,GAAR,QAAQ,CAAU;;;;QAlB9B,oBAAe,GAAoD,EAAE,CAAC;KAkBpC;IAb1C,sBAAI,oDAAc;;;;aAWlB,cAA8C,OAAO,IAAI,CAAC,eAAe,CAAC,EAAE;;;;aAX5E,UAAmB,OAA8B;;YAC/C,IAAM,GAAG,GAA0B,EAAE,CAAC;;gBACtC,KAAgB,IAAA,KAAAA,SAAA,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA,gBAAA,4BAAE;oBAAjC,IAAM,CAAC,WAAA;oBACV,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;iBACvD;;;;;;;;;YACD,IAAI,CAAC,eAAe,GAAG,GAAG,CAAC;SAC5B;;;OAAA;IASD,uCAAI,GAAJ,UAAK,IAAY;QACf,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,EAAE;YAC9B,OAAO,I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