Help Angular by taking a 1 minute survey!Go to surveyHome

TestBedStatic

Static methods implemented by the TestBedViewEngine and TestBedRender3

interface TestBedStatic { new (...args: any[]): TestBed initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): 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 deprecatedOverrideProvider(token: any, provider: { useFactory: Function; deps: any[]; }): void get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any createComponent<T>(component: Type<T>): ComponentFixture<T> }
      
      
  1. interface TestBedStatic {
  2. new (...args: any[]): TestBed
  3. initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed
  4. resetTestEnvironment(): void
  5. resetTestingModule(): TestBedStatic
  6. configureCompiler(config: { providers?: any[]; useJit?: boolean; }): TestBedStatic
  7. configureTestingModule(moduleDef: TestModuleMetadata): TestBedStatic
  8. compileComponents(): Promise<any>
  9. overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic
  10. overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBedStatic
  11. overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBedStatic
  12. overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBedStatic
  13. overrideTemplate(component: Type<any>, template: string): TestBedStatic
  14. overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBedStatic
  15. overrideProvider(token: any, provider: { useFactory: Function; deps: any[]; }): TestBedStatic
  16. deprecatedOverrideProvider(token: any, provider: { useFactory: Function; deps: any[]; }): void
  17. get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any
  18. createComponent<T>(component: Type<T>): ComponentFixture<T>
  19. }

Methods

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

TestBed

initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed
      
      initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed
    
Parameters
ngModule Type | Type[]
platform PlatformRef
aotSummaries () => any[]

Optional. Default is undefined.

Returns

TestBed

Reset the providers for the test injector.

resetTestEnvironment(): void
      
      resetTestEnvironment(): void
    
Parameters

There are no parameters.

Returns

void

resetTestingModule(): TestBedStatic
      
      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
      
      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
      
      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>
      
      compileComponents(): Promise<any>
    
Parameters

There are no parameters.

Returns

Promise<any>

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

TestBedStatic

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

TestBedStatic

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

TestBedStatic

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

TestBedStatic

overrideTemplate(component: Type<any>, template: string): TestBedStatic
      
      overrideTemplate(component: Type<any>, template: string): TestBedStatic
    
Parameters
component Type
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
      
      overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBedStatic
    
Parameters
component Type
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: { useValue: any; }): 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
      
      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.

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

deprecatedOverrideProvider(token: any, provider: { useValue: any; }): void
      
      deprecatedOverrideProvider(token: any, provider: { useValue: any; }): void
    
Parameters
token any
provider { useValue: any; }
Returns

void

deprecatedOverrideProvider(token: any, provider: { useFactory?: Function; useValue?: any; deps?: any[]; }): TestBedStatic
      
      deprecatedOverrideProvider(token: any, provider: { useFactory?: Function; useValue?: any; deps?: any[]; }): TestBedStatic
    
Parameters
token any
provider object
Returns

TestBedStatic

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

Deprecated from v8.0.0 use Type or InjectionToken

Parameters
token any
notFoundValue any

Optional. Default is undefined.

Returns

any

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

ComponentFixture<T>