import { TestBed , async , TestModuleMetadata } from '@angular/core/testing' ; import { Type , CUSTOM_ELEMENTS_SCHEMA } from '@angular/core' ; import { TranslateModule , TranslateLoader } from '@ngx-translate/core' ; import { RouterTestingModule } from '@angular/router/testing' ; import { HttpClientModule , HttpClient } from '@angular/common/http' ; import { ALAIN_I18N_TOKEN , SettingsService , MenuService , ScrollService , _HttpClient } from '@delon/theme' ; import { DelonModule } from 'app/delon.module' ; import { DelonAuthModule } from '@delon/auth' ; import { I18NService } from '@core/i18n/i18n.service' ; import { SharedModule } from '@shared/shared.module' ; import { HttpLoaderFactory } from 'app/app.module' ; const resetTestingModule = TestBed . resetTestingModule , preventAngularFromResetting = ( ) => TestBed . resetTestingModule = ( ) => TestBed ; const allowAngularToReset = ( ) => TestBed . resetTestingModule = resetTestingModule ; export const setUpTestBed = ( moduleDef ) => { beforeAll ( done => ( async ( ) => { resetTestingModule ( ) ; preventAngularFromResetting ( ) ; if ( ! moduleDef . schemas ) moduleDef . schemas = [ ] ; moduleDef . schemas . push ( CUSTOM_ELEMENTS_SCHEMA ) ; if ( ! moduleDef . imports ) moduleDef . imports = [ ] ; moduleDef . imports . push ( RouterTestingModule ) ; moduleDef . imports . push ( HttpClientModule ) ; moduleDef . imports . push ( DelonModule ) ; moduleDef . imports . push ( SharedModule ) ; moduleDef . imports . push ( DelonAuthModule ) ; moduleDef . imports . push ( TranslateModule . forRoot ( { loader : { provide : TranslateLoader , useFactory : ( HttpLoaderFactory ) , deps : [ HttpClient ] } } ) ) ; if ( ! moduleDef . providers ) moduleDef . providers = [ ] ; moduleDef . providers . push ( { provide : ALAIN_I18N_TOKEN , useClass : I18NService , multi : false } ) ; [ SettingsService , MenuService , ScrollService , _HttpClient ] . forEach ( ( item ) => { if ( moduleDef . providers . includes ( item ) ) return ; moduleDef . providers . push ( item ) ; } ) ; TestBed . configureTestingModule ( moduleDef ) ; await TestBed . compileComponents ( ) ; TestBed . resetTestingModule = ( ) => TestBed ; } ) ( ) . then ( done ) . catch ( done . fail ) ) ; afterAll ( ( ) => allowAngularToReset ( ) ) ; } ; /**
 * get service instance
 */ export const getService = < T > ( type ) : T => < T > TestBed . get ( type ) ;