diff --git a/packages/abc/st/test/st-data-source.spec.ts b/packages/abc/st/test/st-data-source.spec.ts index 9a6208635..ec39d9d53 100644 --- a/packages/abc/st/test/st-data-source.spec.ts +++ b/packages/abc/st/test/st-data-source.spec.ts @@ -1,9 +1,11 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { DecimalPipe } from '@angular/common'; import { HttpParams } from '@angular/common/http'; +import { TestBed } from '@angular/core/testing'; import { firstValueFrom, of, throwError } from 'rxjs'; import { DatePipe, YNPipe } from '@delon/theme'; +import { CurrencyService } from '@delon/util/format'; import { deepCopy } from '@delon/util/other'; import { NzSafeAny } from 'ng-zorro-antd/core/types'; @@ -39,7 +41,7 @@ describe('abc: table: data-souce', () => { let datePipe: DatePipe; let ynPipe: YNPipe; let decimalPipe: DecimalPipe; - let currencySrv: MockCurrencyService; + let currencySrv: CurrencyService; let httpResponse: any; let mockDomSanitizer: MockDomSanitizer; @@ -49,12 +51,6 @@ describe('abc: table: data-souce', () => { } } - class MockCurrencyService { - format(): string { - return ''; - } - } - class MockDomSanitizer { bypassSecurityTrustHtml(val: any): any { return val; @@ -73,13 +69,16 @@ describe('abc: table: data-souce', () => { columns: [{ title: '', index: 'id' }] as _STColumn[], paginator: true }; + TestBed.configureTestingModule({ + providers: [DatePipe, YNPipe, DecimalPipe, CurrencyService] + }); mockDomSanitizer = new MockDomSanitizer() as any; - datePipe = new DatePipe(); - ynPipe = new YNPipe(mockDomSanitizer as any); - decimalPipe = new DecimalPipe('zh-CN'); + datePipe = TestBed.inject(DatePipe); + ynPipe = TestBed.inject(YNPipe); + decimalPipe = TestBed.inject(DecimalPipe); http = new MockHttpClient(); - currencySrv = new MockCurrencyService(); - srv = new STDataSource(http as any, datePipe, ynPipe, decimalPipe, currencySrv as any, mockDomSanitizer as any); + currencySrv = TestBed.inject(CurrencyService); + srv = new STDataSource(http as any, datePipe, ynPipe, decimalPipe, currencySrv, mockDomSanitizer as any); srv.setCog(ST_DEFAULT_CONFIG); } diff --git a/packages/abc/st/test/st.spec.ts b/packages/abc/st/test/st.spec.ts index 2b285bd35..db7e32fcd 100644 --- a/packages/abc/st/test/st.spec.ts +++ b/packages/abc/st/test/st.spec.ts @@ -5,15 +5,8 @@ import { By } from '@angular/platform-browser'; import { Router } from '@angular/router'; import { of, Subject, throwError } from 'rxjs'; -import { - DatePipe, - DelonLocaleService, - DrawerHelper, - en_US, - ModalHelper, - _HttpClient, - AlainI18NService -} from '@delon/theme'; +import { DelonLocaleService, DrawerHelper, en_US, ModalHelper, _HttpClient, AlainI18NService } from '@delon/theme'; +import { formatDate } from '@delon/util/date-time'; import { deepCopy } from '@delon/util/other'; import { NzPaginationComponent } from 'ng-zorro-antd/pagination'; import { NzTooltipDirective } from 'ng-zorro-antd/tooltip'; @@ -258,7 +251,7 @@ describe('abc: st', () => { it(`should be render date`, fakeAsync(() => { page .updateColumn([{ title: '', index: 'date', type: 'date' }]) - .expectCell(new DatePipe().transform(MOCKDATE, 'yyyy-MM-dd HH:mm')) + .expectCell(formatDate(MOCKDATE, 'yyyy-MM-dd HH:mm')) .asyncEnd(); })); it(`should be custom render date format`, fakeAsync(() => { @@ -271,7 +264,7 @@ describe('abc: st', () => { dateFormat: 'yyyy-MM' } ]) - .expectCell(new DatePipe().transform(MOCKDATE, 'yyyy-MM')) + .expectCell(formatDate(MOCKDATE, 'yyyy-MM')) .asyncEnd(); })); it(`should be text center`, fakeAsync(() => {