What it does
Configures and initializes environment for unit testing and provides methods for creating components and services in unit tests.
Class Overview
class TestBed implements Injector {staticinitTestEnvironment(ngModule: Type<any>, platform: PlatformRef) : TestBed
staticresetTestEnvironment()
staticresetTestingModule() : typeof TestBed
staticconfigureCompiler(config: {providers?: any[]; useJit?: boolean;}) : typeof TestBed
staticconfigureTestingModule(moduleDef: TestModuleMetadata) : typeof TestBed
staticcompileComponents() : Promise<any>
staticoverrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>) : typeof TestBed
staticoverrideComponent(component: Type<any>, override: MetadataOverride<Component>) : typeof TestBed
staticoverrideDirective(directive: Type<any>, override: MetadataOverride<Directive>) : typeof TestBed
staticoverridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>) : typeof TestBed
staticget(token: any, notFoundValue?: any)
staticcreateComponent(component: Type<T>) : ComponentFixture<T>
initTestEnvironment(ngModule: Type<any>, platform: PlatformRef)
resetTestEnvironment()
resetTestingModule()
platform: PlatformRef
ngModule: Type<any>
configureCompiler(config: {providers?: any[], useJit?: boolean})
configureTestingModule(moduleDef: TestModuleMetadata)
compileComponents() : Promise<any>
get(token: any, notFoundValue?: any)
execute(tokens: any[], fn: Function, context?: any) : any
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>) : void
overrideComponent(component: Type<any>, override: MetadataOverride<Component>) : void
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>) : void
overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>) : void
createComponent(component: Type<T>) : ComponentFixture<T>
}
Class Description
TestBed is the primary api for writing unit tests for Angular applications and libraries.
Static Members
initTestEnvironment(ngModule: Type<any>, platform: PlatformRef) : TestBedInitialize 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/
resetTestEnvironment()Reset the providers for the test injector.
resetTestingModule() : typeof TestBedconfigureCompiler(config: {providers?: any[]; useJit?: boolean;}) : typeof TestBedAllows overriding default compiler providers and settings which are defined in test_injector.js
configureTestingModule(moduleDef: TestModuleMetadata) : typeof TestBedAllows overriding default providers, directives, pipes, modules of the test injector, which are defined in test_injector.js
compileComponents() : Promise<any>Compile components with a templateUrl for the test's NgModule.
It is necessary to call this function
as fetching urls is asynchronous.
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>) : typeof TestBedoverrideComponent(component: Type<any>, override: MetadataOverride<Component>) : typeof TestBedoverrideDirective(directive: Type<any>, override: MetadataOverride<Directive>) : typeof TestBedoverridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>) : typeof TestBedget(token: any, notFoundValue?: any)createComponent(component: Type<T>) : ComponentFixture<T>Class Details
initTestEnvironment(ngModule: Type<any>, platform: PlatformRef)
Initialize 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/
resetTestEnvironment()
Reset the providers for the test injector.
resetTestingModule()
platform : PlatformRef
ngModule : Type<any>
configureCompiler(config: {providers?: any[], useJit?: boolean})
configureTestingModule(moduleDef: TestModuleMetadata)
compileComponents() : Promise<any>
get(token: any, notFoundValue?: any)
execute(tokens: any[], fn: Function, context?: any) : any
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>) : void
overrideComponent(component: Type<any>, override: MetadataOverride<Component>) : void
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>) : void
overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>) : void
createComponent(component: Type<T>) : ComponentFixture<T>
exported from @angular/core/testing/index, defined in @angular/core/testing/test_bed.ts