https://github.com/angular/angular
Tip revision: f6c229f755a56c2a795e9e68dce263c5d3c2b57c authored by Andrew Scott on 16 March 2022, 18:26:17 UTC
release: cut the v13.2.7 release (#45363)
release: cut the v13.2.7 release (#45363)
Tip revision: f6c229f
test_bed_common.ts
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Component, Directive, InjectFlags, InjectionToken, NgModule, Pipe, PlatformRef, ProviderToken, SchemaMetadata, Type} from '@angular/core';
import {ComponentFixture} from './component_fixture';
import {MetadataOverride} from './metadata_override';
import {TestBed} from './test_bed';
/** Whether test modules should be torn down by default. */
export const TEARDOWN_TESTING_MODULE_ON_DESTROY_DEFAULT = true;
/**
* An abstract class for inserting the root test component element in a platform independent way.
*
* @publicApi
*/
export class TestComponentRenderer {
insertRootElement(rootElementId: string) {}
removeAllRootElements?() {}
}
/**
* @publicApi
*/
export const ComponentFixtureAutoDetect =
new InjectionToken<boolean[]>('ComponentFixtureAutoDetect');
/**
* @publicApi
*/
export const ComponentFixtureNoNgZone = new InjectionToken<boolean[]>('ComponentFixtureNoNgZone');
/**
* @publicApi
*/
export type TestModuleMetadata = {
providers?: any[],
declarations?: any[],
imports?: any[],
schemas?: Array<SchemaMetadata|any[]>,
/**
* @deprecated With Ivy, AOT summary files are unused.
*/
aotSummaries?: () => any[],
teardown?: ModuleTeardownOptions;
};
/**
* @publicApi
*/
export interface TestEnvironmentOptions {
/**
* Provides a way to specify AOT summaries to use in TestBed.
* This parameter is unused and deprecated in Ivy.
*
* @deprecated With Ivy, AOT summary files are unused.
*/
aotSummaries?: () => any[];
/**
* Configures the test module teardown behavior in `TestBed`.
*/
teardown?: ModuleTeardownOptions;
}
/**
* Configures the test module teardown behavior in `TestBed`.
* @publicApi
*/
export interface ModuleTeardownOptions {
/** Whether the test module should be destroyed after every test. */
destroyAfterEach: boolean;
/** Whether errors during test module destruction should be re-thrown. Defaults to `true`. */
rethrowErrors?: boolean;
}
/**
* Static methods implemented by the `TestBedViewEngine` and `TestBedRender3`
*
* @publicApi
*/
export interface TestBedStatic {
new(...args: 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'.
*/
initTestEnvironment(
ngModule: Type<any>|Type<any>[], platform: PlatformRef,
options?: TestEnvironmentOptions): 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'.
*
* @deprecated This API that allows providing AOT summaries is deprecated, since summary files are
* unused in Ivy.
*/
initTestEnvironment(
ngModule: Type<any>|Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed;
/**
* Reset the providers for the test injector.
*/
resetTestEnvironment(): void;
resetTestingModule(): TestBedStatic;
/**
* Allows overriding default compiler providers and settings
* which are defined in test_injector.js
*/
configureCompiler(config: {providers?: any[]; useJit?: boolean;}): TestBedStatic;
/**
* Allows overriding default providers, directives, pipes, modules of the test injector,
* which are defined in test_injector.js
*/
configureTestingModule(moduleDef: TestModuleMetadata): 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>;
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;
/**
* Overrides the template of the given component, compiling the template
* in the context of the TestingModule.
*
* Note: This works for JIT and AOTed components as well.
*/
overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBedStatic;
/**
* Overwrites all providers for the given token with the given provider definition.
*
* Note: This works for JIT and AOTed components as well.
*/
overrideProvider(token: any, provider: {
useFactory: Function,
deps: any[],
}): TestBedStatic;
overrideProvider(token: any, provider: {useValue: any;}): TestBedStatic;
overrideProvider(token: any, provider: {
useFactory?: Function,
useValue?: any,
deps?: any[],
}): TestBedStatic;
inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T|null;
/** @deprecated from v9.0.0 use TestBed.inject */
get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
/** @deprecated from v9.0.0 use TestBed.inject */
get(token: any, notFoundValue?: any): any;
createComponent<T>(component: Type<T>): ComponentFixture<T>;
}