@angular/router
Version:
Angular - the routing library
1 lines • 9.38 kB
Source Map (JSON)
{"version":3,"file":"testing.mjs","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 LLC 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} from '@angular/common';\nimport {provideLocationMocks} from '@angular/common/testing';\nimport {Compiler, inject, Injector, ModuleWithProviders, NgModule} from '@angular/core';\nimport {ChildrenOutletContexts, ExtraOptions, NoPreloading, Route, Router, ROUTER_CONFIGURATION, RouteReuseStrategy, RouterModule, ROUTES, Routes, TitleStrategy, UrlHandlingStrategy, UrlSerializer, ɵflatten as flatten, ɵROUTER_PROVIDERS as ROUTER_PROVIDERS, ɵwithPreloading as withPreloading} from '@angular/router';\n\nfunction isUrlHandlingStrategy(opts: ExtraOptions|\n UrlHandlingStrategy): 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\nfunction throwInvalidConfigError(parameter: string): never {\n throw new Error(\n `Parameter ${parameter} does not match the one available in the injector. ` +\n '`setupTestingRouter` is meant to be used as a factory function with dependencies coming from DI.');\n}\n\n/**\n * Router setup factory function used for testing.\n *\n * @publicApi\n * @deprecated Use `provideRouter` or `RouterTestingModule` instead.\n */\nexport function setupTestingRouter(\n urlSerializer: UrlSerializer, contexts: ChildrenOutletContexts, location: Location,\n compiler: Compiler, injector: Injector, routes: Route[][],\n opts?: ExtraOptions|UrlHandlingStrategy|null, urlHandlingStrategy?: UrlHandlingStrategy,\n routeReuseStrategy?: RouteReuseStrategy, titleStrategy?: TitleStrategy) {\n // Note: The checks below are to detect misconfigured providers and invalid uses of\n // `setupTestingRouter`. This function is not used internally (neither in router code or anywhere\n // in g3). It appears this function was exposed as publicApi by mistake and should not be used\n // externally either. However, if it is, the documented intent is to be used as a factory function\n // and parameter values should always match what's available in DI.\n if (urlSerializer !== inject(UrlSerializer)) {\n throwInvalidConfigError('urlSerializer');\n }\n if (contexts !== inject(ChildrenOutletContexts)) {\n throwInvalidConfigError('contexts');\n }\n if (location !== inject(Location)) {\n throwInvalidConfigError('location');\n }\n if (compiler !== inject(Compiler)) {\n throwInvalidConfigError('compiler');\n }\n if (injector !== inject(Injector)) {\n throwInvalidConfigError('injector');\n }\n if (routes !== inject(ROUTES)) {\n throwInvalidConfigError('routes');\n }\n if (opts) {\n // Handle deprecated argument ordering.\n if (isUrlHandlingStrategy(opts)) {\n if (opts !== inject(UrlHandlingStrategy)) {\n throwInvalidConfigError('opts (UrlHandlingStrategy)');\n }\n } else {\n if (opts !== inject(ROUTER_CONFIGURATION)) {\n throwInvalidConfigError('opts (ROUTER_CONFIGURATION)');\n }\n }\n }\n\n if (urlHandlingStrategy !== inject(UrlHandlingStrategy)) {\n throwInvalidConfigError('urlHandlingStrategy');\n }\n\n if (routeReuseStrategy !== inject(RouteReuseStrategy)) {\n throwInvalidConfigError('routeReuseStrategy');\n }\n\n if (titleStrategy !== inject(TitleStrategy)) {\n throwInvalidConfigError('titleStrategy');\n }\n\n return new 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` and `LocationStrategy`.\n *\n * @usageNotes\n * ### Example\n *\n * ```\n * beforeEach(() => {\n * TestBed.configureTestingModule({\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,\n provideLocationMocks(),\n withPreloading(NoPreloading).ɵproviders,\n {provide: ROUTES, multi: true, useValue: []},\n ]\n})\nexport class RouterTestingModule {\n static withRoutes(routes: Routes, config?: ExtraOptions):\n ModuleWithProviders<RouterTestingModule> {\n return {\n ngModule: RouterTestingModule,\n providers: [\n {provide: ROUTES, multi: true, useValue: routes},\n {provide: ROUTER_CONFIGURATION, useValue: config ? config : {}},\n ]\n };\n }\n}\n","/**\n * @license\n * Copyright Google LLC 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 LLC 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 LLC 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":["ROUTER_PROVIDERS","withPreloading"],"mappings":";;;;;;;;;;;;AAaA,SAAS,qBAAqB,CAAC,IACmB,EAAA;;;IAGhD,OAAO,kBAAkB,IAAI,IAAI,CAAC;AACpC,CAAC;AAED,SAAS,uBAAuB,CAAC,SAAiB,EAAA;AAChD,IAAA,MAAM,IAAI,KAAK,CACX,CAAA,UAAA,EAAa,SAAS,CAAqD,mDAAA,CAAA;AAC3E,QAAA,kGAAkG,CAAC,CAAC;AAC1G,CAAC;AAED;;;;;AAKG;AACG,SAAU,kBAAkB,CAC9B,aAA4B,EAAE,QAAgC,EAAE,QAAkB,EAClF,QAAkB,EAAE,QAAkB,EAAE,MAAiB,EACzD,IAA4C,EAA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