blob: 8d61d3a46bb351b3fdeb36ec31b46609a5ea28a8 [file] [log] [blame]
{"version":3,"file":"testing.js","sources":["../../../packages/router/testing/src/router_testing_module.js","../../../packages/router/testing/src/testing.js","../../../packages/router/testing/public_api.js","../../../packages/router/testing/testing.js"],"sourcesContent":["/**\n * @fileoverview added by tsickle\n * @suppress {checkTypes} checked by tsc\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 */\nimport { Location, LocationStrategy } from '@angular/common';\nimport { MockLocationStrategy, SpyLocation } from '@angular/common/testing';\nimport { Compiler, Injectable, Injector, NgModule, NgModuleFactoryLoader, Optional } from '@angular/core';\nimport { ChildrenOutletContexts, NoPreloading, PreloadingStrategy, ROUTER_CONFIGURATION, ROUTES, Router, RouterModule, UrlHandlingStrategy, UrlSerializer, provideRoutes, ɵROUTER_PROVIDERS as ROUTER_PROVIDERS, ɵflatten as flatten } from '@angular/router';\n/**\n * \\@whatItDoes Allows to simulate the loading of ng modules in tests.\n *\n * \\@howToUse\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 * \\@stable\n */\nexport class SpyNgModuleFactoryLoader {\n /**\n * @param {?} compiler\n */\n constructor(compiler) {\n this.compiler = compiler;\n /**\n * \\@docsNotRequired\n */\n this._stubbedModules = {};\n }\n /**\n * \\@docsNotRequired\n * @param {?} modules\n * @return {?}\n */\n set stubbedModules(modules) {\n const /** @type {?} */ res = {};\n for (const /** @type {?} */ t of Object.keys(modules)) {\n res[t] = this.compiler.compileModuleAsync(modules[t]);\n }\n this._stubbedModules = res;\n }\n /**\n * \\@docsNotRequired\n * @return {?}\n */\n get stubbedModules() { return this._stubbedModules; }\n /**\n * @param {?} path\n * @return {?}\n */\n load(path) {\n if (this._stubbedModules[path]) {\n return this._stubbedModules[path];\n }\n else {\n return /** @type {?} */ (Promise.reject(new Error(`Cannot find module ${path}`)));\n }\n }\n}\nSpyNgModuleFactoryLoader.decorators = [\n { type: Injectable },\n];\n/** @nocollapse */\nSpyNgModuleFactoryLoader.ctorParameters = () => [\n { type: Compiler, },\n];\nfunction SpyNgModuleFactoryLoader_tsickle_Closure_declarations() {\n /** @type {!Array<{type: !Function, args: (undefined|!Array<?>)}>} */\n SpyNgModuleFactoryLoader.decorators;\n /**\n * @nocollapse\n * @type {function(): !Array<(null|{type: ?, decorators: (undefined|!Array<{type: !Function, args: (undefined|!Array<?>)}>)})>}\n */\n SpyNgModuleFactoryLoader.ctorParameters;\n /**\n * \\@docsNotRequired\n * @type {?}\n */\n SpyNgModuleFactoryLoader.prototype._stubbedModules;\n /** @type {?} */\n SpyNgModuleFactoryLoader.prototype.compiler;\n}\n/**\n * @param {?} opts\n * @return {?}\n */\nfunction isUrlHandlingStrategy(opts) {\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 * Router setup factory function used for testing.\n *\n * \\@stable\n * @param {?} urlSerializer\n * @param {?} contexts\n * @param {?} location\n * @param {?} loader\n * @param {?} compiler\n * @param {?} injector\n * @param {?} routes\n * @param {?=} opts\n * @param {?=} urlHandlingStrategy\n * @return {?}\n */\nexport function setupTestingRouter(urlSerializer, contexts, location, loader, compiler, injector, routes, opts, urlHandlingStrategy) {\n const /** @type {?} */ router = new Router(/** @type {?} */ ((null)), urlSerializer, contexts, location, injector, loader, compiler, flatten(routes));\n // Handle deprecated argument ordering.\n if (opts) {\n if (isUrlHandlingStrategy(opts)) {\n router.urlHandlingStrategy = opts;\n }\n else if (opts.paramsInheritanceStrategy) {\n router.paramsInheritanceStrategy = opts.paramsInheritanceStrategy;\n }\n }\n if (urlHandlingStrategy) {\n router.urlHandlingStrategy = urlHandlingStrategy;\n }\n return router;\n}\n/**\n * \\@whatItDoes Sets up the router to be used for testing.\n *\n * \\@howToUse\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 * \\@description\n *\n * The modules sets up the router to be used for testing.\n * It provides spy implementations of {\\@link Location}, {\\@link LocationStrategy}, and {\\@link\n * NgModuleFactoryLoader}.\n *\n * \\@stable\n */\nexport class RouterTestingModule {\n /**\n * @param {?} routes\n * @param {?=} config\n * @return {?}\n */\n static withRoutes(routes, config) {\n return {\n ngModule: RouterTestingModule,\n providers: [\n provideRoutes(routes),\n { provide: ROUTER_CONFIGURATION, useValue: config ? config : {} },\n ]\n };\n }\n}\nRouterTestingModule.decorators = [\n { type: NgModule, args: [{\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 },] },\n];\n/** @nocollapse */\nRouterTestingModule.ctorParameters = () => [];\nfunction RouterTestingModule_tsickle_Closure_declarations() {\n /** @type {!Array<{type: !Function, args: (undefined|!Array<?>)}>} */\n RouterTestingModule.decorators;\n /**\n * @nocollapse\n * @type {function(): !Array<(null|{type: ?, decorators: (undefined|!Array<{type: !Function, args: (undefined|!Array<?>)}>)})>}\n */\n RouterTestingModule.ctorParameters;\n}\n//# sourceMappingURL=router_testing_module.js.map","/**\n * @fileoverview added by tsickle\n * @suppress {checkTypes} checked by tsc\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 * @module\n * @description\n * Entry point for all public APIs of the router/testing package.\n */\nexport { SpyNgModuleFactoryLoader, setupTestingRouter, RouterTestingModule } from './router_testing_module';\n//# sourceMappingURL=testing.js.map","/**\n * @fileoverview added by tsickle\n * @suppress {checkTypes} checked by tsc\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 * @module\n * @description\n * Entry point for all public APIs of this package.\n */\nexport { SpyNgModuleFactoryLoader, setupTestingRouter, RouterTestingModule } from './src/testing';\n// This file only reexports content of the `src` folder. Keep it that way.\n//# sourceMappingURL=public_api.js.map","/**\n * @fileoverview added by tsickle\n * @suppress {checkTypes} checked by tsc\n */\n/**\n * Generated bundle index. Do not edit.\n */\nexport { SpyNgModuleFactoryLoader, setupTestingRouter, RouterTestingModule } from './public_api';\n//# sourceMappingURL=testing.js.map"],"names":["flatten","ROUTER_PROVIDERS"],"mappings":";;;;;;;;;;AAAA;;;;;;;;;;;AAWA,AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,AAAO,MAAM,wBAAwB,CAAC;;;;IAIlC,WAAW,CAAC,QAAQ,EAAE;QAClB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;;;;QAIzB,IAAI,CAAC,eAAe,GAAG,EAAE,CAAC;KAC7B;;;;;;IAMD,IAAI,cAAc,CAAC,OAAO,EAAE;QACxB,uBAAuB,GAAG,GAAG,EAAE,CAAC;QAChC,KAAK,uBAAuB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