angular / 14.0.0 / api / core / testing / testbedstatic.html /

TestBedStatic

interface

Static methods implemented by the TestBedViewEngine and TestBedRender3

interface TestBedStatic {
  new (...args: any[]): TestBed
  initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, options?: TestEnvironmentOptions): TestBed
  resetTestEnvironment(): void
  resetTestingModule(): TestBedStatic
  configureCompiler(config: { providers?: any[]; useJit?: boolean; }): TestBedStatic
  configureTestingModule(moduleDef: TestModuleMetadata): TestBedStatic
  compileComponents(): Promise<any>
  overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic
  overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBedStatic
  overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBedStatic
  overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBedStatic
  overrideTemplate(component: Type<any>, template: string): TestBedStatic
  overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBedStatic
  overrideProvider(token: any, provider: { useFactory: Function; deps: any[]; }): TestBedStatic
  inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T
  get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any
  createComponent<T>(component: Type<T>): ComponentFixture<T>
}

Methods

new (...args: any[]): TestBed

Parameters
args any[]
Returns

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.

initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, options?: TestEnvironmentOptions): TestBed

Parameters
ngModule Type<any> | Type<any>[]
platform PlatformRef
options TestEnvironmentOptions

Optional. Default is undefined.

Returns

TestBed

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'.

Reset the providers for the test injector.

resetTestEnvironment(): void

Parameters

There are no parameters.

Returns

void

resetTestingModule(): TestBedStatic

Parameters

There are no parameters.

Returns

TestBedStatic

Allows overriding default compiler providers and settings which are defined in test_injector.js

configureCompiler(config: { providers?: any[]; useJit?: boolean; }): TestBedStatic

Parameters
config object
Returns

TestBedStatic

Allows overriding default providers, directives, pipes, modules of the test injector, which are defined in test_injector.js

configureTestingModule(moduleDef: TestModuleMetadata): TestBedStatic

Parameters
moduleDef TestModuleMetadata
Returns

TestBedStatic

Compile components with a templateUrl for the test's NgModule. It is necessary to call this function as fetching urls is asynchronous.

compileComponents(): Promise<any>

Parameters

There are no parameters.

Returns

Promise<any>

overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic

Parameters
ngModule Type<any>
override MetadataOverride<NgModule>
Returns

TestBedStatic

overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBedStatic

Parameters
component Type<any>
override MetadataOverride<Component>
Returns

TestBedStatic

overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBedStatic

Parameters
directive Type<any>
override MetadataOverride<Directive>
Returns

TestBedStatic

overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBedStatic

Parameters
pipe Type<any>
override MetadataOverride<Pipe>
Returns

TestBedStatic

overrideTemplate(component: Type<any>, template: string): TestBedStatic

Parameters
component Type<any>
template string
Returns

TestBedStatic

Overrides the template of the given component, compiling the template in the context of the TestingModule.

overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBedStatic

Parameters
component Type<any>
template string
Returns

TestBedStatic

Note: This works for JIT and AOTed components as well.

Overwrites all providers for the given token with the given provider definition.

overrideProvider(token: any, provider: { useFactory: Function; deps: any[]; }): TestBedStatic

Parameters
token any
provider object
Returns

TestBedStatic

overrideProvider(token: any, provider: { useValue: any; }): TestBedStatic

Parameters
token any
provider { useValue: any; }
Returns

TestBedStatic

overrideProvider(token: any, provider: { useFactory?: Function; useValue?: any; deps?: any[]; }): TestBedStatic

Parameters
token any
provider object
Returns

TestBedStatic

Note: This works for JIT and AOTed components as well.

inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T

Parameters
token ProviderToken<T>
notFoundValue T

Optional. Default is undefined.

flags InjectFlags

Optional. Default is undefined.

Returns

T

inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T | null

Parameters
token ProviderToken<T>
notFoundValue null
flags InjectFlags

Optional. Default is undefined.

Returns

T | null

get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any

Deprecated from v9.0.0 use TestBed.inject

Parameters
token ProviderToken<T>
notFoundValue T

Optional. Default is undefined.

flags InjectFlags

Optional. Default is undefined.

Returns

any

get(token: any, notFoundValue?: any): any

Deprecated from v9.0.0 use TestBed.inject

Parameters
token any
notFoundValue any

Optional. Default is undefined.

Returns

any

createComponent<T>(component: Type<T>): ComponentFixture<T>

Parameters
component Type<T>
Returns

ComponentFixture<T>

© 2010–2022 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/core/testing/TestBedStatic