Repository navigation
Expand file tree
/
Copy pathrouter_testing_module.ts
More file actions
74 lines (72 loc) · 1.96 KB
/
Copy pathrouter_testing_module.ts
File metadata and controls
74 lines (72 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* @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.dev/license
*/
import {provideLocationMocks} from '@angular/common/testing';
import {ModuleWithProviders, NgModule} from '@angular/core';
import {
ExtraOptions,
NoPreloading,
ROUTER_CONFIGURATION,
RouterModule,
ROUTES,
Routes,
withPreloading,
ɵROUTER_PROVIDERS as ROUTER_PROVIDERS,
} from '../../index';
/**
* @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` and `LocationStrategy`.
*
* @usageNotes
* ### Example
*
* ```ts
* beforeEach(() => {
* TestBed.configureTestingModule({
* imports: [
* RouterModule.forRoot(
* [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}]
* )
* ]
* });
* });
* ```
*
* @publicApi
* @deprecated Use `provideRouter` or `RouterModule`/`RouterModule.forRoot` instead.
* This module was previously used to provide a helpful collection of test fakes,
* most notably those for `Location` and `LocationStrategy`. These are generally not
* required anymore, as `MockPlatformLocation` is provided in `TestBed` by default.
* However, you can use them directly with `provideLocationMocks`.
*/
@NgModule({
exports: [RouterModule],
providers: [
ROUTER_PROVIDERS,
provideLocationMocks(),
withPreloading(NoPreloading).ɵproviders,
{provide: ROUTES, multi: true, useValue: []},
],
})
export class RouterTestingModule {
static withRoutes(
routes: Routes,
config?: ExtraOptions,
): ModuleWithProviders<RouterTestingModule> {
return {
ngModule: RouterTestingModule,
providers: [
{provide: ROUTES, multi: true, useValue: routes},
{provide: ROUTER_CONFIGURATION, useValue: config ? config : {}},
],
};
}
}