You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
226 lines
7.8 KiB
226 lines
7.8 KiB
/**
|
|
* @license Angular v12.2.16
|
|
* (c) 2010-2021 Google LLC. https://angular.io/
|
|
* License: MIT
|
|
*/
|
|
|
|
import { Location, LocationStrategy } from '@angular/common';
|
|
import { SpyLocation, MockLocationStrategy } from '@angular/common/testing';
|
|
import { Injectable, Compiler, NgModule, NgModuleFactoryLoader, Injector, Optional } from '@angular/core';
|
|
import { Router, ɵflatten, ɵassignExtraOptionsToRouter, provideRoutes, ROUTER_CONFIGURATION, RouterModule, ɵROUTER_PROVIDERS, UrlSerializer, ChildrenOutletContexts, ROUTES, UrlHandlingStrategy, RouteReuseStrategy, PreloadingStrategy, NoPreloading } from '@angular/router';
|
|
|
|
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
/**
|
|
* @description
|
|
*
|
|
* Allows to simulate the loading of ng modules in tests.
|
|
*
|
|
* ```
|
|
* const loader = TestBed.inject(NgModuleFactoryLoader);
|
|
*
|
|
* @Component({template: 'lazy-loaded'})
|
|
* class LazyLoadedComponent {}
|
|
* @NgModule({
|
|
* declarations: [LazyLoadedComponent],
|
|
* imports: [RouterModule.forChild([{path: 'loaded', component: LazyLoadedComponent}])]
|
|
* })
|
|
*
|
|
* class LoadedModule {}
|
|
*
|
|
* // sets up stubbedModules
|
|
* loader.stubbedModules = {lazyModule: LoadedModule};
|
|
*
|
|
* router.resetConfig([
|
|
* {path: 'lazy', loadChildren: 'lazyModule'},
|
|
* ]);
|
|
*
|
|
* router.navigateByUrl('/lazy/loaded');
|
|
* ```
|
|
*
|
|
* @publicApi
|
|
*/
|
|
import * as ɵngcc0 from '@angular/core';
|
|
class SpyNgModuleFactoryLoader {
|
|
constructor(compiler) {
|
|
this.compiler = compiler;
|
|
/**
|
|
* @docsNotRequired
|
|
*/
|
|
this._stubbedModules = {};
|
|
}
|
|
/**
|
|
* @docsNotRequired
|
|
*/
|
|
set stubbedModules(modules) {
|
|
const res = {};
|
|
for (const t of Object.keys(modules)) {
|
|
res[t] = this.compiler.compileModuleAsync(modules[t]);
|
|
}
|
|
this._stubbedModules = res;
|
|
}
|
|
/**
|
|
* @docsNotRequired
|
|
*/
|
|
get stubbedModules() {
|
|
return this._stubbedModules;
|
|
}
|
|
load(path) {
|
|
if (this._stubbedModules[path]) {
|
|
return this._stubbedModules[path];
|
|
}
|
|
else {
|
|
return Promise.reject(new Error(`Cannot find module ${path}`));
|
|
}
|
|
}
|
|
}
|
|
SpyNgModuleFactoryLoader.ɵfac = function SpyNgModuleFactoryLoader_Factory(t) { return new (t || SpyNgModuleFactoryLoader)(ɵngcc0.ɵɵinject(ɵngcc0.Compiler)); };
|
|
SpyNgModuleFactoryLoader.ɵprov = /*@__PURE__*/ ɵngcc0.ɵɵdefineInjectable({ token: SpyNgModuleFactoryLoader, factory: SpyNgModuleFactoryLoader.ɵfac });
|
|
SpyNgModuleFactoryLoader.ctorParameters = () => [
|
|
{ type: Compiler }
|
|
];
|
|
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(SpyNgModuleFactoryLoader, [{
|
|
type: Injectable
|
|
}], function () { return [{ type: ɵngcc0.Compiler }]; }, null); })();
|
|
function isUrlHandlingStrategy(opts) {
|
|
// This property check is needed because UrlHandlingStrategy is an interface and doesn't exist at
|
|
// runtime.
|
|
return 'shouldProcessUrl' in opts;
|
|
}
|
|
/**
|
|
* Router setup factory function used for testing.
|
|
*
|
|
* @publicApi
|
|
*/
|
|
function setupTestingRouter(urlSerializer, contexts, location, loader, compiler, injector, routes, opts, urlHandlingStrategy, routeReuseStrategy) {
|
|
const router = new Router(null, urlSerializer, contexts, location, injector, loader, compiler, ɵflatten(routes));
|
|
if (opts) {
|
|
// Handle deprecated argument ordering.
|
|
if (isUrlHandlingStrategy(opts)) {
|
|
router.urlHandlingStrategy = opts;
|
|
}
|
|
else {
|
|
// Handle ExtraOptions
|
|
ɵassignExtraOptionsToRouter(opts, router);
|
|
}
|
|
}
|
|
if (urlHandlingStrategy) {
|
|
router.urlHandlingStrategy = urlHandlingStrategy;
|
|
}
|
|
if (routeReuseStrategy) {
|
|
router.routeReuseStrategy = routeReuseStrategy;
|
|
}
|
|
return router;
|
|
}
|
|
/**
|
|
* @description
|
|
*
|
|
* Sets up the router to be used for testing.
|
|
*
|
|
* The modules sets up the router to be used for testing.
|
|
* It provides spy implementations of `Location`, `LocationStrategy`, and {@link
|
|
* NgModuleFactoryLoader}.
|
|
*
|
|
* @usageNotes
|
|
* ### Example
|
|
*
|
|
* ```
|
|
* beforeEach(() => {
|
|
* TestBed.configureTestingModule({
|
|
* imports: [
|
|
* RouterTestingModule.withRoutes(
|
|
* [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}]
|
|
* )
|
|
* ]
|
|
* });
|
|
* });
|
|
* ```
|
|
*
|
|
* @publicApi
|
|
*/
|
|
class RouterTestingModule {
|
|
static withRoutes(routes, config) {
|
|
return {
|
|
ngModule: RouterTestingModule,
|
|
providers: [
|
|
provideRoutes(routes),
|
|
{ provide: ROUTER_CONFIGURATION, useValue: config ? config : {} },
|
|
]
|
|
};
|
|
}
|
|
}
|
|
RouterTestingModule.ɵfac = function RouterTestingModule_Factory(t) { return new (t || RouterTestingModule)(); };
|
|
RouterTestingModule.ɵmod = /*@__PURE__*/ ɵngcc0.ɵɵdefineNgModule({ type: RouterTestingModule });
|
|
RouterTestingModule.ɵinj = /*@__PURE__*/ ɵngcc0.ɵɵdefineInjector({ providers: [
|
|
ɵROUTER_PROVIDERS, { provide: Location, useClass: SpyLocation },
|
|
{ provide: LocationStrategy, useClass: MockLocationStrategy },
|
|
{ provide: NgModuleFactoryLoader, useClass: SpyNgModuleFactoryLoader }, {
|
|
provide: Router,
|
|
useFactory: setupTestingRouter,
|
|
deps: [
|
|
UrlSerializer, ChildrenOutletContexts, Location, NgModuleFactoryLoader, Compiler, Injector,
|
|
ROUTES, ROUTER_CONFIGURATION, [UrlHandlingStrategy, new Optional()],
|
|
[RouteReuseStrategy, new Optional()]
|
|
]
|
|
},
|
|
{ provide: PreloadingStrategy, useExisting: NoPreloading }, provideRoutes([])
|
|
], imports: [RouterModule] });
|
|
(function () { (typeof ngDevMode === "undefined" || ngDevMode) && ɵngcc0.ɵsetClassMetadata(RouterTestingModule, [{
|
|
type: NgModule,
|
|
args: [{
|
|
exports: [RouterModule],
|
|
providers: [
|
|
ɵROUTER_PROVIDERS, { provide: Location, useClass: SpyLocation },
|
|
{ provide: LocationStrategy, useClass: MockLocationStrategy },
|
|
{ provide: NgModuleFactoryLoader, useClass: SpyNgModuleFactoryLoader }, {
|
|
provide: Router,
|
|
useFactory: setupTestingRouter,
|
|
deps: [
|
|
UrlSerializer, ChildrenOutletContexts, Location, NgModuleFactoryLoader, Compiler, Injector,
|
|
ROUTES, ROUTER_CONFIGURATION, [UrlHandlingStrategy, new Optional()],
|
|
[RouteReuseStrategy, new Optional()]
|
|
]
|
|
},
|
|
{ provide: PreloadingStrategy, useExisting: NoPreloading }, provideRoutes([])
|
|
]
|
|
}]
|
|
}], null, null); })();
|
|
(function () { (typeof ngJitMode === "undefined" || ngJitMode) && ɵngcc0.ɵɵsetNgModuleScope(RouterTestingModule, { exports: function () { return [RouterModule]; } }); })();
|
|
|
|
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
// This file only reexports content of the `src` folder. Keep it that way.
|
|
|
|
/**
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.io/license
|
|
*/
|
|
|
|
/**
|
|
* Generated bundle index. Do not edit.
|
|
*/
|
|
|
|
export { RouterTestingModule, SpyNgModuleFactoryLoader, setupTestingRouter };
|
|
|
|
//# sourceMappingURL=testing.js.map
|