From 667740ac7e135e6a41c31835ea9d5e3f95038ccf Mon Sep 17 00:00:00 2001 From: cipchk Date: Mon, 1 Jul 2024 14:33:10 +0800 Subject: [PATCH] perf(*): clean deprecated of angular libs --- packages/abc/cell/cell.spec.ts | 3 +-- packages/abc/down-file/down-file.spec.ts | 9 +++---- packages/abc/exception/exception.spec.ts | 5 ++-- .../abc/full-content/full-content.spec.ts | 3 +-- .../abc/global-footer/global-footer.spec.ts | 6 ++--- packages/abc/notice-icon/notice-icon.spec.ts | 8 ++++--- packages/abc/onboarding/onboarding.spec.ts | 6 ++--- packages/abc/page-header/page-header.spec.ts | 23 +++++++++--------- .../abc/reuse-tab/reuse-tab.component.spec.ts | 5 ++-- packages/abc/st/test/base.spec.ts | 10 ++++---- packages/abc/xlsx/xlsx.spec.ts | 8 ++++--- packages/acl/src/acl-guard.spec.ts | 13 +++++----- .../auth/src/social/social.service.spec.ts | 10 ++++---- .../auth/src/token/base.interceptor.spec.ts | 12 +++------- packages/auth/src/token/jwt/jwt.guard.spec.ts | 7 +++--- .../src/token/jwt/jwt.interceptor.spec.ts | 10 ++++---- .../src/token/simple/simple.guard.spec.ts | 7 +++--- .../token/simple/simple.interceptor.spec.ts | 5 ++-- packages/cache/src/cache.spec.ts | 7 +++--- packages/form/spec/base.spec.ts | 13 ++++------ .../layout-nav.component.spec.ts | 24 +++++++------------ .../layout-default/layout.component.spec.ts | 11 ++++++--- packages/theme/src/services/http/http.spec.ts | 7 +++--- packages/theme/src/services/i18n/i18n.spec.ts | 13 ++++------ .../src/services/title/title.service.spec.ts | 5 ++-- 25 files changed, 105 insertions(+), 125 deletions(-) diff --git a/packages/abc/cell/cell.spec.ts b/packages/abc/cell/cell.spec.ts index 666780f92..874dbd465 100644 --- a/packages/abc/cell/cell.spec.ts +++ b/packages/abc/cell/cell.spec.ts @@ -3,7 +3,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { BrowserModule, By, DomSanitizer } from '@angular/platform-browser'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; import { Router } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; import { of } from 'rxjs'; import { cleanCdkOverlayHtml, createTestContext } from '@delon/testing'; @@ -29,7 +28,7 @@ describe('abc: cell', () => { const moduleAction = (): void => { TestBed.configureTestingModule({ - imports: [CellModule, NoopAnimationsModule, BrowserModule, RouterTestingModule.withRoutes([]), NzIconTestModule], + imports: [CellModule, NoopAnimationsModule, BrowserModule, NzIconTestModule], declarations: [TestComponent, TestWidget] }); }; diff --git a/packages/abc/down-file/down-file.spec.ts b/packages/abc/down-file/down-file.spec.ts index 2349f68ec..7b0e6e558 100644 --- a/packages/abc/down-file/down-file.spec.ts +++ b/packages/abc/down-file/down-file.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable deprecation/deprecation */ -import { HttpHeaders, HttpResponse } from '@angular/common/http'; -import { HttpClientTestingModule, HttpTestingController, TestRequest } from '@angular/common/http/testing'; +import { HttpHeaders, HttpResponse, provideHttpClient } from '@angular/common/http'; +import { HttpTestingController, TestRequest, provideHttpClientTesting } from '@angular/common/http/testing'; import { Component, DebugElement } from '@angular/core'; import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; @@ -27,8 +27,9 @@ describe('abc: down-file', () => { function createComp(): void { TestBed.configureTestingModule({ - imports: [HttpClientTestingModule, DownFileModule], - declarations: [TestComponent] + imports: [DownFileModule], + declarations: [TestComponent], + providers: [provideHttpClient(), provideHttpClientTesting()] }); fixture = TestBed.createComponent(TestComponent); diff --git a/packages/abc/exception/exception.spec.ts b/packages/abc/exception/exception.spec.ts index f03176615..ea074ef83 100644 --- a/packages/abc/exception/exception.spec.ts +++ b/packages/abc/exception/exception.spec.ts @@ -2,7 +2,7 @@ import { Directionality } from '@angular/cdk/bidi'; import { Component, DebugElement, ViewChild } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { RouterTestingModule } from '@angular/router/testing'; +import { provideRouter } from '@angular/router'; import { createTestContext } from '@delon/testing'; import { DelonLocaleModule, DelonLocaleService, en_US } from '@delon/theme'; @@ -17,7 +17,8 @@ describe('abc: exception', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ExceptionModule, DelonLocaleModule, RouterTestingModule], + imports: [ExceptionModule, DelonLocaleModule], + providers: [provideRouter([])], declarations: [TestComponent] }); ({ fixture, dl, context } = createTestContext(TestComponent)); diff --git a/packages/abc/full-content/full-content.spec.ts b/packages/abc/full-content/full-content.spec.ts index 908decca7..fb4040f26 100644 --- a/packages/abc/full-content/full-content.spec.ts +++ b/packages/abc/full-content/full-content.spec.ts @@ -3,7 +3,6 @@ import { Component, CUSTOM_ELEMENTS_SCHEMA, DebugElement, ViewChild } from '@ang import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { ActivationEnd, Router } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; import { BehaviorSubject } from 'rxjs'; import { NzSafeAny } from 'ng-zorro-antd/core/types'; @@ -22,7 +21,7 @@ describe('abc: full-content', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [FullContentModule, RouterTestingModule.withRoutes([])], + imports: [FullContentModule], declarations: [TestComponent], schemas: [CUSTOM_ELEMENTS_SCHEMA], providers: [{ provide: APP_BASE_HREF, useValue: '/' }] diff --git a/packages/abc/global-footer/global-footer.spec.ts b/packages/abc/global-footer/global-footer.spec.ts index 83122fef0..42bc440e2 100644 --- a/packages/abc/global-footer/global-footer.spec.ts +++ b/packages/abc/global-footer/global-footer.spec.ts @@ -2,8 +2,7 @@ import { APP_BASE_HREF } from '@angular/common'; import { Component, CUSTOM_ELEMENTS_SCHEMA, DebugElement } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { Router } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; +import { provideRouter, Router } from '@angular/router'; import { WINDOW } from '@delon/util/token'; @@ -32,10 +31,11 @@ describe('abc: global-footer', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [RouterTestingModule.withRoutes([]), GlobalFooterModule], + imports: [GlobalFooterModule], schemas: [CUSTOM_ELEMENTS_SCHEMA], declarations: [TestComponent], providers: [ + provideRouter([]), { provide: APP_BASE_HREF, useValue: '/' }, { provide: WINDOW, useFactory: () => new MockWindow() } ] diff --git a/packages/abc/notice-icon/notice-icon.spec.ts b/packages/abc/notice-icon/notice-icon.spec.ts index 2f1d7a2f7..5cae88d79 100644 --- a/packages/abc/notice-icon/notice-icon.spec.ts +++ b/packages/abc/notice-icon/notice-icon.spec.ts @@ -1,4 +1,5 @@ -import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { provideHttpClient } from '@angular/common/http'; +import { provideHttpClientTesting } from '@angular/common/http/testing'; import { Component, DebugElement, ViewChild } from '@angular/core'; import { ComponentFixture, discardPeriodicTasks, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; @@ -20,8 +21,9 @@ describe('abc: notice-icon', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [NoopAnimationsModule, NoticeIconModule, HttpClientTestingModule, DelonLocaleModule], - declarations: [TestComponent] + imports: [NoopAnimationsModule, NoticeIconModule, DelonLocaleModule], + declarations: [TestComponent], + providers: [provideHttpClient(), provideHttpClientTesting()] }); ({ fixture, dl, context } = createTestContext(TestComponent)); }); diff --git a/packages/abc/onboarding/onboarding.spec.ts b/packages/abc/onboarding/onboarding.spec.ts index 22e9aa560..7949bf336 100644 --- a/packages/abc/onboarding/onboarding.spec.ts +++ b/packages/abc/onboarding/onboarding.spec.ts @@ -1,8 +1,7 @@ import { Component } from '@angular/core'; import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { Router } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; +import { provideRouter, Router } from '@angular/router'; import { throwError } from 'rxjs'; import { createTestContext } from '@delon/testing'; @@ -20,7 +19,8 @@ describe('abc: onboarding', () => { function genModule(): void { TestBed.configureTestingModule({ - imports: [OnboardingModule, NoopAnimationsModule, RouterTestingModule], + imports: [OnboardingModule, NoopAnimationsModule], + providers: [provideRouter([])], declarations: [TestComponent] }); ({ fixture } = createTestContext(TestComponent)); diff --git a/packages/abc/page-header/page-header.spec.ts b/packages/abc/page-header/page-header.spec.ts index c48cefc28..720bf54ac 100644 --- a/packages/abc/page-header/page-header.spec.ts +++ b/packages/abc/page-header/page-header.spec.ts @@ -2,8 +2,7 @@ import { APP_BASE_HREF } from '@angular/common'; import { Component, DebugElement, ViewChild } from '@angular/core'; import { ComponentFixture, fakeAsync, flush, TestBed, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { Router } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; +import { Router, provideRouter } from '@angular/router'; import { createTestContext } from '@delon/testing'; import { @@ -36,12 +35,12 @@ describe('abc: page-header', () => { let router: Router; function genModule(other: { template?: string; providers?: NzSafeAny[]; created?: boolean }): void { - const imports = [ - RouterTestingModule.withRoutes([{ path: '1-1/:name', component: TestComponent }]), - PageHeaderModule, - AlainThemeModule + const imports = [PageHeaderModule, AlainThemeModule]; + const providers = [ + provideRouter([{ path: '1-1/:name', component: TestComponent }]), + { provide: APP_BASE_HREF, useValue: '/' }, + SettingsService ]; - const providers = [{ provide: APP_BASE_HREF, useValue: '/' }, SettingsService]; if (other.providers && other.providers.length) { providers.push(...other.providers); } @@ -75,12 +74,12 @@ describe('abc: page-header', () => { describe('', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - RouterTestingModule.withRoutes([{ path: '1-1/:name', component: TestComponent }]), - PageHeaderModule, - AlainThemeModule + imports: [PageHeaderModule, AlainThemeModule], + providers: [ + provideRouter([{ path: '1-1/:name', component: TestComponent }]), + { provide: APP_BASE_HREF, useValue: '/' }, + SettingsService ], - providers: [{ provide: APP_BASE_HREF, useValue: '/' }, SettingsService], declarations: [TestComponent, TestAutoBreadcrumbComponent, TestI18nComponent] }); }); diff --git a/packages/abc/reuse-tab/reuse-tab.component.spec.ts b/packages/abc/reuse-tab/reuse-tab.component.spec.ts index 64f53fc4a..bbf80a146 100644 --- a/packages/abc/reuse-tab/reuse-tab.component.spec.ts +++ b/packages/abc/reuse-tab/reuse-tab.component.spec.ts @@ -2,8 +2,7 @@ import { Component, DebugElement, Injectable, TemplateRef, ViewChild } from '@an import { ComponentFixture, discardPeriodicTasks, fakeAsync, flush, TestBed, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { ExtraOptions, RouteReuseStrategy, ROUTER_CONFIGURATION } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; +import { ExtraOptions, RouteReuseStrategy, ROUTER_CONFIGURATION, RouterModule } from '@angular/router'; import { Observable, of } from 'rxjs'; import { ALAIN_I18N_TOKEN, DelonLocaleModule, DelonLocaleService, en_US, MenuService, zh_CN } from '@delon/theme'; @@ -47,7 +46,7 @@ describe('abc: reuse-tab', () => { DelonLocaleModule, ReuseTabComponent, NoopAnimationsModule, - RouterTestingModule.withRoutes( + RouterModule.forRoot( [ { path: '', diff --git a/packages/abc/st/test/base.spec.ts b/packages/abc/st/test/base.spec.ts index bf5a2df11..96b2ec690 100644 --- a/packages/abc/st/test/base.spec.ts +++ b/packages/abc/st/test/base.spec.ts @@ -1,11 +1,12 @@ import { CommonModule } from '@angular/common'; -import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { provideHttpClient } from '@angular/common/http'; +import { provideHttpClientTesting } from '@angular/common/http/testing'; import { Component, DebugElement, Injectable, TemplateRef, Type, ViewChild } from '@angular/core'; import { ComponentFixture, discardPeriodicTasks, flush, TestBed, tick } from '@angular/core/testing'; import { FormsModule } from '@angular/forms'; import { By } from '@angular/platform-browser'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { RouterTestingModule } from '@angular/router/testing'; +import { RouterModule } from '@angular/router'; import { Observable } from 'rxjs'; import { dispatchDropDown } from '@delon/testing'; @@ -102,14 +103,15 @@ export function genModule( NoopAnimationsModule, CommonModule, FormsModule, - HttpClientTestingModule, - RouterTestingModule.withRoutes([]), + RouterModule.forRoot([]), NzModalModule, NzDrawerModule, STModule, DelonLocaleModule ]; const providers = [ + provideHttpClient(), + provideHttpClientTesting(), { provide: ALAIN_I18N_TOKEN, useClass: MockI18NServiceFake diff --git a/packages/abc/xlsx/xlsx.spec.ts b/packages/abc/xlsx/xlsx.spec.ts index 05c5dc789..5f841b726 100644 --- a/packages/abc/xlsx/xlsx.spec.ts +++ b/packages/abc/xlsx/xlsx.spec.ts @@ -1,5 +1,5 @@ -import { HttpClient } from '@angular/common/http'; -import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { HttpClient, provideHttpClient } from '@angular/common/http'; +import { provideHttpClientTesting } from '@angular/common/http/testing'; import { Component, DebugElement } from '@angular/core'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; @@ -29,9 +29,11 @@ describe('abc: xlsx', () => { let srv: XlsxService; function genModule(): void { TestBed.configureTestingModule({ - imports: [XlsxModule, HttpClientTestingModule], + imports: [XlsxModule], declarations: [TestComponent], providers: [ + provideHttpClient(), + provideHttpClientTesting(), { provide: HttpClient, useClass: MockHttpClient }, { provide: LazyService, useClass: MockLazyService } ] diff --git a/packages/acl/src/acl-guard.spec.ts b/packages/acl/src/acl-guard.spec.ts index 53b27a71c..d8c23a611 100644 --- a/packages/acl/src/acl-guard.spec.ts +++ b/packages/acl/src/acl-guard.spec.ts @@ -1,7 +1,6 @@ import { Component } from '@angular/core'; import { TestBed } from '@angular/core/testing'; -import { Router } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; +import { Router, provideRouter } from '@angular/router'; import { of } from 'rxjs'; import { ACLGuardService, aclCanActivate, aclCanActivateChild, aclCanMatch } from './acl-guard'; @@ -18,8 +17,8 @@ describe('acl: guard', () => { beforeEach(() => { TestBed.configureTestingModule({ declarations: [TestComponent], - imports: [ - RouterTestingModule.withRoutes([ + providers: [ + provideRouter([ { path: '403', component: TestComponent }, { path: 'canActivate', @@ -39,9 +38,9 @@ describe('acl: guard', () => { canMatch: [aclCanMatch], data: { guard: { role: ['admin'] } } as ACLGuardData } - ]), - DelonACLModule - ] + ]) + ], + imports: [DelonACLModule] }); srv = TestBed.inject(ACLGuardService); acl = TestBed.inject(ACLService); diff --git a/packages/auth/src/social/social.service.spec.ts b/packages/auth/src/social/social.service.spec.ts index 2a84f6640..ef4048b5d 100644 --- a/packages/auth/src/social/social.service.spec.ts +++ b/packages/auth/src/social/social.service.spec.ts @@ -1,9 +1,9 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { DOCUMENT } from '@angular/common'; -import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { provideHttpClient } from '@angular/common/http'; +import { provideHttpClientTesting } from '@angular/common/http/testing'; import { discardPeriodicTasks, fakeAsync, TestBed, tick } from '@angular/core/testing'; -import { DefaultUrlSerializer, Router } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; +import { DefaultUrlSerializer, Router, provideRouter } from '@angular/router'; import { DA_SERVICE_TOKEN, ITokenModel } from '../token/interface'; import { SimpleTokenModel } from '../token/simple/simple.model'; @@ -51,8 +51,10 @@ describe('auth: social.service', () => { function genModule(tokenData?: SimpleTokenModel): void { TestBed.configureTestingModule({ - imports: [HttpClientTestingModule, RouterTestingModule.withRoutes([])], providers: [ + provideHttpClient(), + provideHttpClientTesting(), + provideRouter([]), SocialService, { provide: DOCUMENT, useClass: MockDocument }, { provide: Router, useValue: mockRouter } diff --git a/packages/auth/src/token/base.interceptor.spec.ts b/packages/auth/src/token/base.interceptor.spec.ts index 6dd6858d8..16a8289be 100644 --- a/packages/auth/src/token/base.interceptor.spec.ts +++ b/packages/auth/src/token/base.interceptor.spec.ts @@ -1,16 +1,10 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { DOCUMENT } from '@angular/common'; import { HttpClient, HttpContext, provideHttpClient, withInterceptors } from '@angular/common/http'; -import { - HttpClientTestingModule, - HttpTestingController, - TestRequest, - provideHttpClientTesting -} from '@angular/common/http/testing'; +import { HttpTestingController, TestRequest, provideHttpClientTesting } from '@angular/common/http/testing'; import { Type } from '@angular/core'; import { TestBed } from '@angular/core/testing'; -import { Router } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; +import { Router, provideRouter } from '@angular/router'; import { Observable } from 'rxjs'; import { AlainAuthConfig, provideAlainConfig } from '@delon/util/config'; @@ -67,8 +61,8 @@ describe('auth: base.interceptor', () => { function genModule(options: AlainAuthConfig, tokenData?: ITokenModel, provider: any[] = []): void { TestBed.configureTestingModule({ - imports: [HttpClientTestingModule, RouterTestingModule.withRoutes([])], providers: [ + provideRouter([]), { provide: DOCUMENT, useValue: MockDoc }, provideHttpClient(withInterceptors([authSimpleInterceptor])), provideHttpClientTesting(), diff --git a/packages/auth/src/token/jwt/jwt.guard.spec.ts b/packages/auth/src/token/jwt/jwt.guard.spec.ts index 46aa98950..246978a5e 100644 --- a/packages/auth/src/token/jwt/jwt.guard.spec.ts +++ b/packages/auth/src/token/jwt/jwt.guard.spec.ts @@ -1,7 +1,6 @@ import { Component, NgModule } from '@angular/core'; import { fakeAsync, TestBed } from '@angular/core/testing'; -import { Router } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; +import { Router, provideRouter } from '@angular/router'; import { DA_SERVICE_TOKEN, ITokenService } from '../interface'; import { authJWTCanActivate, authJWTCanActivateChild, authJWTCanMatch } from './jwt.guard'; @@ -13,8 +12,8 @@ describe('auth: JWTGuard', () => { beforeEach(() => { TestBed.configureTestingModule({ declarations: [MockComponent], - imports: [ - RouterTestingModule.withRoutes([ + providers: [ + provideRouter([ { path: 'home', component: MockComponent, diff --git a/packages/auth/src/token/jwt/jwt.interceptor.spec.ts b/packages/auth/src/token/jwt/jwt.interceptor.spec.ts index e9afdf645..fa8d717a6 100644 --- a/packages/auth/src/token/jwt/jwt.interceptor.spec.ts +++ b/packages/auth/src/token/jwt/jwt.interceptor.spec.ts @@ -2,7 +2,7 @@ import { HttpClient, provideHttpClient, withInterceptors } from '@angular/common import { HttpTestingController, TestRequest, provideHttpClientTesting } from '@angular/common/http/testing'; import { Component, Type } from '@angular/core'; import { TestBed } from '@angular/core/testing'; -import { RouterTestingModule } from '@angular/router/testing'; +import { provideRouter } from '@angular/router'; import { of, catchError } from 'rxjs'; import { AlainAuthConfig, provideAlainConfig } from '@delon/util/config'; @@ -30,15 +30,13 @@ describe('auth: jwt.interceptor', () => { function genModule(options: AlainAuthConfig, tokenData?: JWTTokenModel): void { TestBed.configureTestingModule({ declarations: [MockComponent], - imports: [ - RouterTestingModule.withRoutes([ + providers: [ + provideRouter([ { path: 'login', component: MockComponent } - ]) - ], - providers: [ + ]), provideHttpClient(withInterceptors([authJWTInterceptor])), provideHttpClientTesting(), provideAlainConfig({ auth: options }), diff --git a/packages/auth/src/token/simple/simple.guard.spec.ts b/packages/auth/src/token/simple/simple.guard.spec.ts index 2f1a79e1f..07ae61434 100644 --- a/packages/auth/src/token/simple/simple.guard.spec.ts +++ b/packages/auth/src/token/simple/simple.guard.spec.ts @@ -1,7 +1,6 @@ import { Component, NgModule } from '@angular/core'; import { fakeAsync, TestBed } from '@angular/core/testing'; -import { Router } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; +import { Router, provideRouter } from '@angular/router'; import { DA_SERVICE_TOKEN, ITokenService } from '../interface'; import { authSimpleCanActivate, authSimpleCanActivateChild, authSimpleCanMatch } from './simple.guard'; @@ -13,8 +12,8 @@ describe('auth: SimpleGuard', () => { beforeEach(() => { TestBed.configureTestingModule({ declarations: [MockComponent], - imports: [ - RouterTestingModule.withRoutes([ + providers: [ + provideRouter([ { path: 'home', component: MockComponent, diff --git a/packages/auth/src/token/simple/simple.interceptor.spec.ts b/packages/auth/src/token/simple/simple.interceptor.spec.ts index 39c91db9e..c891f0037 100644 --- a/packages/auth/src/token/simple/simple.interceptor.spec.ts +++ b/packages/auth/src/token/simple/simple.interceptor.spec.ts @@ -3,8 +3,7 @@ import { HttpClient, provideHttpClient, withInterceptors } from '@angular/common import { HttpTestingController, TestRequest, provideHttpClientTesting } from '@angular/common/http/testing'; import { Type } from '@angular/core'; import { TestBed } from '@angular/core/testing'; -import { DefaultUrlSerializer, Router } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; +import { DefaultUrlSerializer, Router, provideRouter } from '@angular/router'; import { Observable } from 'rxjs'; import { AlainAuthConfig, provideAlainConfig } from '@delon/util/config'; @@ -56,8 +55,8 @@ describe('auth: simple.interceptor', () => { function genModule(options: AlainAuthConfig, tokenData?: SimpleTokenModel): void { TestBed.configureTestingModule({ - imports: [RouterTestingModule.withRoutes([])], providers: [ + provideRouter([]), provideHttpClient(withInterceptors([authSimpleInterceptor])), provideHttpClientTesting(), provideAlainConfig({ auth: options }), diff --git a/packages/cache/src/cache.spec.ts b/packages/cache/src/cache.spec.ts index 33d169314..2fcf2119a 100644 --- a/packages/cache/src/cache.spec.ts +++ b/packages/cache/src/cache.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { HttpClient } from '@angular/common/http'; -import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; +import { HttpClient, provideHttpClient } from '@angular/common/http'; +import { HttpTestingController, provideHttpClientTesting } from '@angular/common/http/testing'; import { Type } from '@angular/core'; import { TestBed } from '@angular/core/testing'; import { firstValueFrom, Observable, of, filter } from 'rxjs'; @@ -36,12 +36,11 @@ describe('cache: service', () => { }); function genModule(options?: AlainCacheConfig): void { - const providers: any[] = []; + const providers: any[] = [provideHttpClient(), provideHttpClientTesting()]; if (options) { providers.push(provideAlainConfig({ cache: options })); } TestBed.configureTestingModule({ - imports: [HttpClientTestingModule], providers }); diff --git a/packages/form/spec/base.spec.ts b/packages/form/spec/base.spec.ts index dfafacfc4..3c2d4b24d 100644 --- a/packages/form/spec/base.spec.ts +++ b/packages/form/spec/base.spec.ts @@ -1,4 +1,5 @@ -import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { provideHttpClient } from '@angular/common/http'; +import { provideHttpClientTesting } from '@angular/common/http/testing'; import { Component, DebugElement, ViewChild } from '@angular/core'; import { ComponentFixture, discardPeriodicTasks, TestBed, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; @@ -77,15 +78,9 @@ export function builder(options?: { export function configureSFTestSuite(options?: { imports?: NzSafeAny[]; widgets?: SFWidgetProvideConfig[] }): void { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - NoopAnimationsModule, - AlainThemeModule, - DelonFormModule, - HttpClientTestingModule, - ...(options?.imports ?? []) - ], + imports: [NoopAnimationsModule, AlainThemeModule, DelonFormModule, ...(options?.imports ?? [])], declarations: [TestFormComponent], - providers: [provideSFConfig({ widgets: options?.widgets })] + providers: [provideHttpClient(), provideHttpClientTesting(), provideSFConfig({ widgets: options?.widgets })] }); }); } diff --git a/packages/theme/layout-default/layout-nav.component.spec.ts b/packages/theme/layout-default/layout-nav.component.spec.ts index 0c17bdac4..439c2d639 100644 --- a/packages/theme/layout-default/layout-nav.component.spec.ts +++ b/packages/theme/layout-default/layout-nav.component.spec.ts @@ -1,11 +1,11 @@ import { DOCUMENT } from '@angular/common'; -import { HttpClientTestingModule } from '@angular/common/http/testing'; +import { provideHttpClient } from '@angular/common/http'; +import { provideHttpClientTesting } from '@angular/common/http/testing'; import { Component, DebugElement, ViewChild } from '@angular/core'; import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { Router, RouterModule } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; +import { Router, RouterModule, provideRouter } from '@angular/router'; import { ACLService } from '@delon/acl'; import { AlainThemeModule, MenuIcon, MenuService, SettingsService } from '@delon/theme'; @@ -101,15 +101,11 @@ describe('theme: layout-default-nav', () => { function createModule(): void { TestBed.configureTestingModule({ - imports: [ - NoopAnimationsModule, - RouterModule.forRoot([]), - AlainThemeModule, - HttpClientTestingModule, - LayoutDefaultModule - ], + imports: [NoopAnimationsModule, RouterModule.forRoot([]), AlainThemeModule, LayoutDefaultModule], declarations: [TestComponent], providers: [ + provideHttpClient(), + provideHttpClientTesting(), { provide: ACLService, useClass: MockACLService }, { provide: WINDOW, useFactory: () => new MockWindow() } ] @@ -546,11 +542,9 @@ describe('theme: layout-default-nav', () => { describe('should be recursive path', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [ - RouterModule.forRoot([]), - AlainThemeModule, - LayoutDefaultModule, - RouterTestingModule.withRoutes([ + imports: [RouterModule.forRoot([]), AlainThemeModule, LayoutDefaultModule], + providers: [ + provideRouter([ { path: 'user', component: TestRouteComponent }, { path: 'user2', component: TestRouteComponent }, { path: 'user/type', component: TestRouteComponent } diff --git a/packages/theme/layout-default/layout.component.spec.ts b/packages/theme/layout-default/layout.component.spec.ts index d554c389e..111f44dd4 100644 --- a/packages/theme/layout-default/layout.component.spec.ts +++ b/packages/theme/layout-default/layout.component.spec.ts @@ -1,8 +1,13 @@ import { Component, DebugElement, TemplateRef, ViewChild } from '@angular/core'; import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { NavigationCancel, NavigationError, RouteConfigLoadEnd, RouteConfigLoadStart } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; +import { + NavigationCancel, + NavigationError, + RouteConfigLoadEnd, + RouteConfigLoadStart, + RouterModule +} from '@angular/router'; import { createTestContext } from '@delon/testing'; import { NzIconTestModule } from 'ng-zorro-antd/icon/testing'; @@ -23,7 +28,7 @@ describe('theme: layout-default', () => { beforeEach(() => { TestBed.configureTestingModule({ - imports: [LayoutDefaultModule, RouterTestingModule, NzIconTestModule, AlainThemeModule], + imports: [LayoutDefaultModule, RouterModule.forRoot([]), NzIconTestModule, AlainThemeModule], declarations: [TestComponent] }); diff --git a/packages/theme/src/services/http/http.spec.ts b/packages/theme/src/services/http/http.spec.ts index 48c6124ea..9455dd1be 100644 --- a/packages/theme/src/services/http/http.spec.ts +++ b/packages/theme/src/services/http/http.spec.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { HttpParams, HttpResponse } from '@angular/common/http'; -import { HttpClientTestingModule, HttpTestingController, TestRequest } from '@angular/common/http/testing'; +import { HttpParams, HttpResponse, provideHttpClient } from '@angular/common/http'; +import { HttpTestingController, TestRequest, provideHttpClientTesting } from '@angular/common/http/testing'; import { Type } from '@angular/core'; import { fakeAsync, TestBed, tick } from '@angular/core/testing'; import { of, catchError } from 'rxjs'; @@ -22,12 +22,11 @@ describe('theme: http.client', () => { const BODY = 'body data'; function createModule(config?: AlainThemeHttpClientConfig): void { - const providers: any[] = [_HttpClient]; + const providers: any[] = [provideHttpClient(), provideHttpClientTesting(), _HttpClient]; if (config) { providers.push(provideAlainConfig({ themeHttp: config })); } TestBed.configureTestingModule({ - imports: [HttpClientTestingModule], providers }); diff --git a/packages/theme/src/services/i18n/i18n.spec.ts b/packages/theme/src/services/i18n/i18n.spec.ts index 0382dc48b..efd4ac37c 100644 --- a/packages/theme/src/services/i18n/i18n.spec.ts +++ b/packages/theme/src/services/i18n/i18n.spec.ts @@ -1,8 +1,7 @@ import { Component } from '@angular/core'; import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; -import { Router } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; +import { Router, RouterModule } from '@angular/router'; import { provideAlainConfig } from '@delon/util/config'; @@ -110,7 +109,7 @@ describe('theme: i18n', () => { TestBed.configureTestingModule({ imports: [ AlainThemeModule, - RouterTestingModule.withRoutes([ + RouterModule.forRoot([ { path: ':i18n', component: TestComponent, @@ -134,9 +133,7 @@ describe('theme: i18n', () => { TestBed.configureTestingModule({ imports: [ AlainThemeModule, - RouterTestingModule.withRoutes([ - { path: ':invalid', component: TestComponent, canActivate: [alainI18nCanActivate] } - ]) + RouterModule.forRoot([{ path: ':invalid', component: TestComponent, canActivate: [alainI18nCanActivate] }]) ], declarations: [TestComponent] }); @@ -153,9 +150,7 @@ describe('theme: i18n', () => { TestBed.configureTestingModule({ imports: [ AlainThemeModule, - RouterTestingModule.withRoutes([ - { path: ':lang', component: TestComponent, canActivate: [alainI18nCanActivate] } - ]) + RouterModule.forRoot([{ path: ':lang', component: TestComponent, canActivate: [alainI18nCanActivate] }]) ], declarations: [TestComponent], providers: [provideAlainConfig({ themeI18n: { paramNameOfUrlGuard: 'lang' } })] diff --git a/packages/theme/src/services/title/title.service.spec.ts b/packages/theme/src/services/title/title.service.spec.ts index bccd4ee54..81c7fbbb4 100644 --- a/packages/theme/src/services/title/title.service.spec.ts +++ b/packages/theme/src/services/title/title.service.spec.ts @@ -1,8 +1,7 @@ import { DOCUMENT } from '@angular/common'; import { fakeAsync, TestBed, tick } from '@angular/core/testing'; import { Title } from '@angular/platform-browser'; -import { ActivatedRoute } from '@angular/router'; -import { RouterTestingModule } from '@angular/router/testing'; +import { ActivatedRoute, RouterModule } from '@angular/router'; import { of } from 'rxjs'; import { NzSafeAny } from 'ng-zorro-antd/core/types'; @@ -34,7 +33,7 @@ describe('Service: Title', () => { function genModule(providers: NzSafeAny[] = [], loadI18n: boolean = true): void { const i18nProvider: NzSafeAny[] = loadI18n ? [{ provide: ALAIN_I18N_TOKEN, useClass: AlainI18NServiceFake }] : []; TestBed.configureTestingModule({ - imports: [AlainThemeModule, RouterTestingModule], + imports: [AlainThemeModule, RouterModule.forRoot([])], providers: [TitleService, MenuService, { provide: Title, useClass: TestTitleService }, ...i18nProvider].concat( providers )