API
interface TestBed {
readonly platform: PlatformRef;
readonly ngModule: Type<any> | Type<any>[];
initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, options?: TestEnvironmentOptions | undefined): void;
resetTestEnvironment(): void;
resetTestingModule(): TestBed;
configureCompiler(config: { providers?: any[] | undefined; useJit?: boolean | undefined; }): void;
configureTestingModule(moduleDef: TestModuleMetadata): TestBed;
compileComponents(): Promise<any>;
inject<T>(token: ProviderToken<T>, notFoundValue: undefined, options: InjectOptions & { optional?: false | undefined; }): T;
inject<T>(token: ProviderToken<T>, notFoundValue: null | undefined, options: InjectOptions): T | null;
inject<T>(token: ProviderToken<T>, notFoundValue?: T | undefined, options?: InjectOptions | undefined): T;
runInInjectionContext<T>(fn: () => T): T;
execute(tokens: any[], fn: Function, context?: any): any;
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBed;
overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBed;
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBed;
overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBed;
overrideTemplate(component: Type<any>, template: string): TestBed;
overrideProvider(token: any, provider: { useFactory: Function; deps: any[]; multi?: boolean | undefined; }): TestBed;
overrideProvider(token: any, provider: { useValue: any; multi?: boolean | undefined; }): TestBed;
overrideProvider(token: any, provider: { useFactory?: Function | undefined; useValue?: any; deps?: any[] | undefined; multi?: boolean | undefined; }): TestBed;
overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBed;
createComponent<T>(component: Type<T>, options?: TestComponentOptions | undefined): ComponentFixture<T>;
flushEffects(): void;
tick(): void;
readonly platform: PlatformRef;
readonly ngModule: Type<any> | Type<any>[];
initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, options?: TestEnvironmentOptions | undefined): void;
resetTestEnvironment(): void;
resetTestingModule(): TestBed;
configureCompiler(config: { providers?: any[] | undefined; useJit?: boolean | undefined; }): void;
configureTestingModule(moduleDef: TestModuleMetadata): TestBed;
compileComponents(): Promise<any>;
inject<T>(token: ProviderToken<T>, notFoundValue: undefined, options: InjectOptions & { optional?: false | undefined; }): T;
inject<T>(token: ProviderToken<T>, notFoundValue: null | undefined, options: InjectOptions): T | null;
inject<T>(token: ProviderToken<T>, notFoundValue?: T | undefined, options?: InjectOptions | undefined): T;
runInInjectionContext<T>(fn: () => T): T;
execute(tokens: any[], fn: Function, context?: any): any;
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBed;
overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBed;
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBed;
overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBed;
overrideTemplate(component: Type<any>, template: string): TestBed;
overrideProvider(token: any, provider: { useFactory: Function; deps: any[]; multi?: boolean | undefined; }): TestBed;
overrideProvider(token: any, provider: { useValue: any; multi?: boolean | undefined; }): TestBed;
overrideProvider(token: any, provider: { useFactory?: Function | undefined; useValue?: any; deps?: any[] | undefined; multi?: boolean | undefined; }): TestBed;
overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBed;
createComponent<T>(component: Type<T>, options?: TestComponentOptions | undefined): ComponentFixture<T>;
flushEffects(): void;
tick(): void;
}
platform
PlatformRefngModule
Type<any> | Type<any>[]initTestEnvironment
voidInitialize the environment for testing with a compiler factory, a PlatformRef, and an angular module. These are common to every test in the suite.
This may only be called once, to set up the common providers for the current test suite on the current platform. If you absolutely need to change the providers, first use resetTestEnvironment.
Test modules and platforms for individual platforms are available from '@angular/
Type<any> | Type<any>[]
PlatformRef
void
resetTestEnvironment
voidReset the providers for the test injector.
void
configureCompiler
void{ providers?: any[] | undefined; useJit?: boolean | undefined; }
void
compileComponents
Promise<any>Promise<any>
inject
TProviderToken<T>
undefined
InjectOptions & { optional?: false | undefined; }
T
inject
T | nullProviderToken<T>
null | undefined
InjectOptions
T | null
inject
TProviderToken<T>
T | undefined
InjectOptions | undefined
T
runInInjectionContext
Texecute
anyany[]
Function
any
any
overrideModule
TestBedoverrideComponent
TestBedoverrideDirective
TestBedoverridePipe
TestBedoverrideProvider
TestBedOverwrites all providers for the given token with the given provider definition.
any
{ useFactory: Function; deps: any[]; multi?: boolean | undefined; }
TestBed
overrideProvider
TestBedoverrideProvider
TestBedany
{ useFactory?: Function | undefined; useValue?: any; deps?: any[] | undefined; multi?: boolean | undefined; }
TestBed
overrideTemplateUsingTestingModule
TestBedcreateComponent
ComponentFixture<T>flushEffects
voidExecute any pending effects.
void
tick
voidExecute any pending work required to synchronize model to the UI.
void
platform
PlatformRefngModule
Type<any> | Type<any>[]initTestEnvironment
voidInitialize the environment for testing with a compiler factory, a PlatformRef, and an angular module. These are common to every test in the suite.
This may only be called once, to set up the common providers for the current test suite on the current platform. If you absolutely need to change the providers, first use resetTestEnvironment.
Test modules and platforms for individual platforms are available from '@angular/
Type<any> | Type<any>[]
PlatformRef
void
resetTestEnvironment
voidReset the providers for the test injector.
void
configureCompiler
void{ providers?: any[] | undefined; useJit?: boolean | undefined; }
void
compileComponents
Promise<any>Promise<any>
inject
TProviderToken<T>
undefined
InjectOptions & { optional?: false | undefined; }
T
inject
T | nullProviderToken<T>
null | undefined
InjectOptions
T | null
inject
TProviderToken<T>
T | undefined
InjectOptions | undefined
T
runInInjectionContext
Texecute
anyany[]
Function
any
any
overrideModule
TestBedoverrideComponent
TestBedoverrideDirective
TestBedoverridePipe
TestBedoverrideProvider
TestBedOverwrites all providers for the given token with the given provider definition.
any
{ useFactory: Function; deps: any[]; multi?: boolean | undefined; }
TestBed
overrideProvider
TestBedoverrideProvider
TestBedany
{ useFactory?: Function | undefined; useValue?: any; deps?: any[] | undefined; multi?: boolean | undefined; }
TestBed
overrideTemplateUsingTestingModule
TestBedcreateComponent
ComponentFixture<T>flushEffects
voidExecute any pending effects.
void
tick
voidExecute any pending work required to synchronize model to the UI.
void