TestBed
class
npm Package | @angular/core |
---|---|
Module | import { TestBed } from '@angular/core/testing'; |
Source | core/testing/src/test_bed.ts |
Overview
class TestBed implements Injector { static initTestEnvironment(ngModule: Type<any>|Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed static resetTestEnvironment() static resetTestingModule(): typeof TestBed static configureCompiler(config: {providers?: any[]; useJit?: boolean;}): typeof TestBed static configureTestingModule(moduleDef: TestModuleMetadata): typeof TestBed static compileComponents(): Promise<any> static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): typeof TestBed static overrideComponent(component: Type<any>, override: MetadataOverride<Component>): typeof TestBed static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): typeof TestBed static overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): typeof TestBed static overrideTemplate(component: Type<any>, template: string): typeof TestBed static overrideProvider(token: any, provider: {...}): typeof TestBed static deprecatedOverrideProvider(token: any, provider: {...}): typeof TestBed static get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND) static createComponent<T>(component: Type<T>): ComponentFixture<T> platform: PlatformRef ngModule: Type<any>|Type<any>[] initTestEnvironment(ngModule: Type<any>|Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]) resetTestEnvironment() resetTestingModule() configureCompiler(config: {providers?: any[], useJit?: boolean}) configureTestingModule(moduleDef: TestModuleMetadata) compileComponents(): Promise<any> get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND) 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 overrideProvider(token: any, provider: {useFactory?: Function, useValue?: any, deps?: any[]}): void deprecatedOverrideProvider(token: any, provider: {useFactory?: Function, useValue?: any, deps?: any[]}): void createComponent<T>(component: Type<T>): ComponentFixture<T> }
Description
TestBed is the primary api for writing unit tests for Angular applications and libraries.
Static Members
static initTestEnvironment(ngModule: Type<any>|Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed
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/<platform_name>/testing'.
static resetTestEnvironment()
Reset the providers for the test injector.
static resetTestingModule(): typeof TestBed
static configureCompiler(config: {providers?: any[]; useJit?: boolean;}): typeof TestBed
Allows overriding default compiler providers and settings which are defined in test_injector.js
static configureTestingModule(moduleDef: TestModuleMetadata): typeof TestBed
Allows overriding default providers, directives, pipes, modules of the test injector, which are defined in test_injector.js
static 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.
static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): typeof TestBed
static overrideComponent(component: Type<any>, override: MetadataOverride<Component>): typeof TestBed
static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): typeof TestBed
static overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): typeof TestBed
static overrideTemplate(component: Type<any>, template: string): typeof TestBed
static overrideProvider(token: any, provider: {
useFactory?: Function,
useValue?: any,
deps?: any[],
}): typeof TestBed
Overloads
static overrideProvider(token: any, provider: {
useFactory: Function,
deps: any[],
}): void
Overwrites all providers for the given token with the given provider definition.
static overrideProvider(token: any, provider: {useValue: any;}): void
static deprecatedOverrideProvider(token: any, provider: {
useFactory?: Function,
useValue?: any,
deps?: any[],
}): typeof TestBed
Overloads
static deprecatedOverrideProvider(token: any, provider: {
useFactory: Function,
deps: any[],
}): void
Overwrites all providers for the given token with the given provider definition.
static deprecatedOverrideProvider(token: any, provider: {useValue: any;}): void
static get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND)
static createComponent<T>(component: Type<T>): ComponentFixture<T>
Members
platform: PlatformRef
ngModule: Type<any>|Type<any>[]
initTestEnvironment(ngModule: Type<any>|Type<any>[], platform: PlatformRef, aotSummaries?: () => any[])
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/<platform_name>/testing'.
resetTestEnvironment()
Reset the providers for the test injector.
resetTestingModule()
configureCompiler(config: {providers?: any[], useJit?: boolean})
configureTestingModule(moduleDef: TestModuleMetadata)
compileComponents(): Promise<any>
get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND)
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
overrideProvider(token: any, provider: {useFactory?: Function, useValue?: any, deps?: any[]}): void
Overloads
overrideProvider(token: any, provider: {
useFactory: Function,
deps: any[],
}): void
Overwrites all providers for the given token with the given provider definition.
overrideProvider(token: any, provider: {useValue: any;}): void
deprecatedOverrideProvider(token: any, provider: {useFactory?: Function, useValue?: any, deps?: any[]}): void
Overloads
deprecatedOverrideProvider(token: any, provider: {
useFactory: Function,
deps: any[],
}): void
Overwrites all providers for the given token with the given provider definition.
deprecatedOverrideProvider(token: any, provider: {useValue: any;}): void
createComponent<T>(component: Type<T>): ComponentFixture<T>
© 2010–2017 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v4.angular.io/api/core/testing/TestBed