🌐 AI搜索 & 代理 主页
Skip to content

Commit 6148261

Browse files
committed
test: RouterTestingModule migration
1 parent 7c47721 commit 6148261

File tree

3 files changed

+27
-25
lines changed

3 files changed

+27
-25
lines changed

projects/coreui-angular/src/lib/header/header/header.component.spec.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2-
import { RouterTestingModule } from '@angular/router/testing';
3-
import { Router } from '@angular/router';
2+
import { Router, RouterModule } from '@angular/router';
43

54
import { HeaderComponent } from './header.component';
65

@@ -11,10 +10,7 @@ describe('HeaderComponent', () => {
1110

1211
beforeEach(waitForAsync(() => {
1312
TestBed.configureTestingModule({
14-
imports: [
15-
RouterTestingModule.withRoutes([]),
16-
HeaderComponent
17-
]
13+
imports: [HeaderComponent, RouterModule.forRoot([])]
1814
}).compileComponents();
1915
}));
2016

projects/coreui-angular/src/lib/sidebar/sidebar-nav/sidebar-nav.component.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import { RouterModule } from '@angular/router';
12
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
2-
import { RouterTestingModule } from '@angular/router/testing';
33

44
import { SidebarNavComponent } from './sidebar-nav.component';
55
import { SidebarNavHelper } from './sidebar-nav.service';
@@ -12,7 +12,7 @@ describe('SidebarNavComponent', () => {
1212

1313
beforeEach(waitForAsync(() => {
1414
TestBed.configureTestingModule({
15-
imports: [RouterTestingModule.withRoutes([]), SidebarNavComponent],
15+
imports: [SidebarNavComponent, RouterModule.forRoot([])],
1616
declarations: [],
1717
providers: [SidebarNavHelper]
1818
}).compileComponents();

projects/coreui-angular/src/lib/sidebar/sidebar-nav/sidebar-nav.service.spec.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import { TestBed } from '@angular/core/testing';
2-
import { RouterTestingModule } from '@angular/router/testing';
3-
import { Router, Routes } from '@angular/router';
2+
import { Router, RouterModule, Routes } from '@angular/router';
43

54
import { SidebarNavHelper } from './sidebar-nav.service';
65

76
describe('SidebarNavHelper', () => {
87
let service: SidebarNavHelper;
9-
let router: RouterTestingModule;
8+
let router: RouterModule;
109
const routes: Routes = [
1110
{ path: 'dashboard', redirectTo: 'home', pathMatch: 'full' },
1211
{ path: '', redirectTo: 'dashboard', pathMatch: 'full' }
1312
];
1413

1514
beforeEach(() => {
1615
TestBed.configureTestingModule({
17-
imports: [RouterTestingModule.withRoutes(routes)],
16+
imports: [RouterModule.forRoot(routes)],
1817
providers: [SidebarNavHelper]
1918
});
2019

@@ -28,21 +27,26 @@ describe('SidebarNavHelper', () => {
2827
it('should return itemType', () => {
2928
expect(service.itemType({ divider: true })).toEqual('divider');
3029
expect(service.itemType({ title: true })).toEqual('title');
31-
expect(service.itemType({
32-
children: [{
33-
name: 'Dropdown',
34-
url: '/dashboard'
35-
}]
36-
})).toEqual('group');
30+
expect(
31+
service.itemType({
32+
children: [
33+
{
34+
name: 'Dropdown',
35+
url: '/dashboard'
36+
}
37+
]
38+
})
39+
).toEqual('group');
3740
expect(service.itemType({ label: { variant: 'info' } })).toEqual('label');
3841
expect(service.itemType({})).toEqual('empty');
39-
expect(service.itemType({
42+
expect(
43+
service.itemType({
4044
name: 'Disabled',
4145
url: '/dashboard',
4246
icon: 'icon-ban',
4347
attributes: { disabled: true }
44-
}
45-
)).toEqual('link');
48+
})
49+
).toEqual('link');
4650
});
4751

4852
it('should be active', () => {
@@ -60,10 +64,12 @@ describe('SidebarNavHelper', () => {
6064
});
6165

6266
it('should return icon class object', () => {
63-
expect(service.getIconClass({ icon: 'icon-ban' })).toEqual(jasmine.objectContaining({
64-
'nav-icon': true,
65-
'icon-ban': true
66-
}));
67+
expect(service.getIconClass({ icon: 'icon-ban' })).toEqual(
68+
jasmine.objectContaining({
69+
'nav-icon': true,
70+
'icon-ban': true
71+
})
72+
);
6773
expect(service.getIconClass({ icon: 'icon-ban' })).toEqual(jasmine.objectContaining({ 'nav-icon': true }));
6874
expect(service.getIconClass({ icon: '' })).toEqual(jasmine.objectContaining({ 'nav-icon': true }));
6975
});

0 commit comments

Comments
 (0)