refactor(ivy): cleanup the public API for core/testing (#25492)
PR Close #25492
This commit is contained in:
parent
01ec5fd6b0
commit
1f1103913a
|
@ -229,14 +229,8 @@ describe('@angular/core ng_package', () => {
|
||||||
expect(shx.cat('testing.metadata.json'))
|
expect(shx.cat('testing.metadata.json'))
|
||||||
.toContain(`"exports":[{"from":"./testing/testing"}],"flatModuleIndexRedirect":true`);
|
.toContain(`"exports":[{"from":"./testing/testing"}],"flatModuleIndexRedirect":true`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should have an \'actual\' metadata.json file', () => {
|
|
||||||
expect(shx.cat('testing/testing.metadata.json'))
|
|
||||||
.toContain(`"metadata":{"async":{"__symbolic":"function"},`);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('fesm2015', () => {
|
describe('fesm2015', () => {
|
||||||
it('should have a fesm15 file in the /fesm2015 directory',
|
it('should have a fesm15 file in the /fesm2015 directory',
|
||||||
() => { expect(shx.cat('fesm2015/testing.js')).toContain(`export {`); });
|
() => { expect(shx.cat('fesm2015/testing.js')).toContain(`export {`); });
|
||||||
|
|
|
@ -11,7 +11,8 @@ import {Component, Directive, Injector, NgModule, Pipe, PlatformRef, Provider, R
|
||||||
import {ComponentFixture} from './component_fixture';
|
import {ComponentFixture} from './component_fixture';
|
||||||
import {MetadataOverride} from './metadata_override';
|
import {MetadataOverride} from './metadata_override';
|
||||||
import {ComponentResolver, DirectiveResolver, NgModuleResolver, PipeResolver, Resolver} from './resolvers';
|
import {ComponentResolver, DirectiveResolver, NgModuleResolver, PipeResolver, Resolver} from './resolvers';
|
||||||
import {ComponentFixtureAutoDetect, TestComponentRenderer, TestModuleMetadata} from './test_bed_common';
|
import {TestBed} from './test_bed';
|
||||||
|
import {ComponentFixtureAutoDetect, TestBedStatic, TestComponentRenderer, TestModuleMetadata} from './test_bed_common';
|
||||||
|
|
||||||
let _nextRootElementId = 0;
|
let _nextRootElementId = 0;
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ let _nextRootElementId = 0;
|
||||||
* Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
|
* Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
|
||||||
* according to the compiler used.
|
* according to the compiler used.
|
||||||
*/
|
*/
|
||||||
export class TestBedRender3 {
|
export class TestBedRender3 implements Injector, TestBed {
|
||||||
/**
|
/**
|
||||||
* Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
* Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
||||||
* angular module. These are common to every test in the suite.
|
* angular module. These are common to every test in the suite.
|
||||||
|
@ -40,8 +41,7 @@ export class TestBedRender3 {
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
static initTestEnvironment(
|
static initTestEnvironment(
|
||||||
ngModule: Type<any>|Type<any>[], platform: PlatformRef,
|
ngModule: Type<any>|Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed {
|
||||||
aotSummaries?: () => any[]): TestBedRender3 {
|
|
||||||
const testBed = _getTestBedRender3();
|
const testBed = _getTestBedRender3();
|
||||||
testBed.initTestEnvironment(ngModule, platform, aotSummaries);
|
testBed.initTestEnvironment(ngModule, platform, aotSummaries);
|
||||||
return testBed;
|
return testBed;
|
||||||
|
@ -54,18 +54,18 @@ export class TestBedRender3 {
|
||||||
*/
|
*/
|
||||||
static resetTestEnvironment(): void { _getTestBedRender3().resetTestEnvironment(); }
|
static resetTestEnvironment(): void { _getTestBedRender3().resetTestEnvironment(); }
|
||||||
|
|
||||||
static configureCompiler(config: {providers?: any[]; useJit?: boolean;}): typeof TestBedRender3 {
|
static configureCompiler(config: {providers?: any[]; useJit?: boolean;}): TestBedStatic {
|
||||||
_getTestBedRender3().configureCompiler(config);
|
_getTestBedRender3().configureCompiler(config);
|
||||||
return TestBedRender3;
|
return TestBedRender3 as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows overriding default providers, directives, pipes, modules of the test injector,
|
* Allows overriding default providers, directives, pipes, modules of the test injector,
|
||||||
* which are defined in test_injector.js
|
* which are defined in test_injector.js
|
||||||
*/
|
*/
|
||||||
static configureTestingModule(moduleDef: TestModuleMetadata): typeof TestBedRender3 {
|
static configureTestingModule(moduleDef: TestModuleMetadata): TestBedStatic {
|
||||||
_getTestBedRender3().configureTestingModule(moduleDef);
|
_getTestBedRender3().configureTestingModule(moduleDef);
|
||||||
return TestBedRender3;
|
return TestBedRender3 as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,32 +75,31 @@ export class TestBedRender3 {
|
||||||
*/
|
*/
|
||||||
static compileComponents(): Promise<any> { return _getTestBedRender3().compileComponents(); }
|
static compileComponents(): Promise<any> { return _getTestBedRender3().compileComponents(); }
|
||||||
|
|
||||||
static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>):
|
static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic {
|
||||||
typeof TestBedRender3 {
|
|
||||||
_getTestBedRender3().overrideModule(ngModule, override);
|
_getTestBedRender3().overrideModule(ngModule, override);
|
||||||
return TestBedRender3;
|
return TestBedRender3 as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
static overrideComponent(component: Type<any>, override: MetadataOverride<Component>):
|
static overrideComponent(component: Type<any>, override: MetadataOverride<Component>):
|
||||||
typeof TestBedRender3 {
|
TestBedStatic {
|
||||||
_getTestBedRender3().overrideComponent(component, override);
|
_getTestBedRender3().overrideComponent(component, override);
|
||||||
return TestBedRender3;
|
return TestBedRender3 as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>):
|
static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>):
|
||||||
typeof TestBedRender3 {
|
TestBedStatic {
|
||||||
_getTestBedRender3().overrideDirective(directive, override);
|
_getTestBedRender3().overrideDirective(directive, override);
|
||||||
return TestBedRender3;
|
return TestBedRender3 as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
static overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): typeof TestBedRender3 {
|
static overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBedStatic {
|
||||||
_getTestBedRender3().overridePipe(pipe, override);
|
_getTestBedRender3().overridePipe(pipe, override);
|
||||||
return TestBedRender3;
|
return TestBedRender3 as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
static overrideTemplate(component: Type<any>, template: string): typeof TestBedRender3 {
|
static overrideTemplate(component: Type<any>, template: string): TestBedStatic {
|
||||||
_getTestBedRender3().overrideComponent(component, {set: {template, templateUrl: null !}});
|
_getTestBedRender3().overrideComponent(component, {set: {template, templateUrl: null !}});
|
||||||
return TestBedRender3;
|
return TestBedRender3 as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -109,10 +108,9 @@ export class TestBedRender3 {
|
||||||
*
|
*
|
||||||
* Note: This works for JIT and AOTed components as well.
|
* Note: This works for JIT and AOTed components as well.
|
||||||
*/
|
*/
|
||||||
static overrideTemplateUsingTestingModule(component: Type<any>, template: string):
|
static overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBedStatic {
|
||||||
typeof TestBedRender3 {
|
|
||||||
_getTestBedRender3().overrideTemplateUsingTestingModule(component, template);
|
_getTestBedRender3().overrideTemplateUsingTestingModule(component, template);
|
||||||
return TestBedRender3;
|
return TestBedRender3 as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
overrideTemplateUsingTestingModule(component: Type<any>, template: string): void {
|
overrideTemplateUsingTestingModule(component: Type<any>, template: string): void {
|
||||||
|
@ -122,15 +120,15 @@ export class TestBedRender3 {
|
||||||
static overrideProvider(token: any, provider: {
|
static overrideProvider(token: any, provider: {
|
||||||
useFactory: Function,
|
useFactory: Function,
|
||||||
deps: any[],
|
deps: any[],
|
||||||
}): typeof TestBedRender3;
|
}): TestBedStatic;
|
||||||
static overrideProvider(token: any, provider: {useValue: any;}): typeof TestBedRender3;
|
static overrideProvider(token: any, provider: {useValue: any;}): TestBedStatic;
|
||||||
static overrideProvider(token: any, provider: {
|
static overrideProvider(token: any, provider: {
|
||||||
useFactory?: Function,
|
useFactory?: Function,
|
||||||
useValue?: any,
|
useValue?: any,
|
||||||
deps?: any[],
|
deps?: any[],
|
||||||
}): typeof TestBedRender3 {
|
}): TestBedStatic {
|
||||||
_getTestBedRender3().overrideProvider(token, provider);
|
_getTestBedRender3().overrideProvider(token, provider);
|
||||||
return TestBedRender3;
|
return TestBedRender3 as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,7 +145,7 @@ export class TestBedRender3 {
|
||||||
useFactory?: Function,
|
useFactory?: Function,
|
||||||
useValue?: any,
|
useValue?: any,
|
||||||
deps?: any[],
|
deps?: any[],
|
||||||
}): typeof TestBedRender3 {
|
}): TestBedStatic {
|
||||||
throw new Error('Render3TestBed.deprecatedOverrideProvider is not implemented');
|
throw new Error('Render3TestBed.deprecatedOverrideProvider is not implemented');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,9 +157,9 @@ export class TestBedRender3 {
|
||||||
return _getTestBedRender3().createComponent(component);
|
return _getTestBedRender3().createComponent(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
static resetTestingModule(): typeof TestBedRender3 {
|
static resetTestingModule(): TestBedStatic {
|
||||||
_getTestBedRender3().resetTestingModule();
|
_getTestBedRender3().resetTestingModule();
|
||||||
return TestBedRender3;
|
return TestBedRender3 as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
|
|
|
@ -12,7 +12,7 @@ import {AsyncTestCompleter} from './async_test_completer';
|
||||||
import {ComponentFixture} from './component_fixture';
|
import {ComponentFixture} from './component_fixture';
|
||||||
import {MetadataOverride} from './metadata_override';
|
import {MetadataOverride} from './metadata_override';
|
||||||
import {TestBedRender3, _getTestBedRender3} from './r3_test_bed';
|
import {TestBedRender3, _getTestBedRender3} from './r3_test_bed';
|
||||||
import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestComponentRenderer, TestModuleMetadata} from './test_bed_common';
|
import {ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, TestBedStatic, TestComponentRenderer, TestModuleMetadata} from './test_bed_common';
|
||||||
import {TestingCompiler, TestingCompilerFactory} from './test_compiler';
|
import {TestingCompiler, TestingCompilerFactory} from './test_compiler';
|
||||||
|
|
||||||
const UNDEFINED = new Object();
|
const UNDEFINED = new Object();
|
||||||
|
@ -20,6 +20,84 @@ const UNDEFINED = new Object();
|
||||||
|
|
||||||
let _nextRootElementId = 0;
|
let _nextRootElementId = 0;
|
||||||
|
|
||||||
|
export interface TestBed {
|
||||||
|
platform: PlatformRef;
|
||||||
|
|
||||||
|
ngModule: Type<any>|Type<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'.
|
||||||
|
*
|
||||||
|
* @experimental
|
||||||
|
*/
|
||||||
|
initTestEnvironment(
|
||||||
|
ngModule: Type<any>|Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the providers for the test injector.
|
||||||
|
*
|
||||||
|
* @experimental
|
||||||
|
*/
|
||||||
|
resetTestEnvironment(): void;
|
||||||
|
|
||||||
|
resetTestingModule(): void;
|
||||||
|
|
||||||
|
configureCompiler(config: {providers?: any[], useJit?: boolean}): void;
|
||||||
|
|
||||||
|
configureTestingModule(moduleDef: TestModuleMetadata): void;
|
||||||
|
|
||||||
|
compileComponents(): Promise<any>;
|
||||||
|
|
||||||
|
get(token: any, notFoundValue?: any): 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwrites all providers for the given token with the given provider definition.
|
||||||
|
*/
|
||||||
|
overrideProvider(token: any, provider: {
|
||||||
|
useFactory: Function,
|
||||||
|
deps: any[],
|
||||||
|
}): void;
|
||||||
|
overrideProvider(token: any, provider: {useValue: any;}): void;
|
||||||
|
overrideProvider(token: any, provider: {useFactory?: Function, useValue?: any, deps?: any[]}):
|
||||||
|
void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwrites all providers for the given token with the given provider definition.
|
||||||
|
*
|
||||||
|
* @deprecated as it makes all NgModules lazy. Introduced only for migrating off of it.
|
||||||
|
*/
|
||||||
|
deprecatedOverrideProvider(token: any, provider: {
|
||||||
|
useFactory: Function,
|
||||||
|
deps: any[],
|
||||||
|
}): void;
|
||||||
|
deprecatedOverrideProvider(token: any, provider: {useValue: any;}): void;
|
||||||
|
deprecatedOverrideProvider(
|
||||||
|
token: any, provider: {useFactory?: Function, useValue?: any, deps?: any[]}): void;
|
||||||
|
|
||||||
|
|
||||||
|
overrideTemplateUsingTestingModule(component: Type<any>, template: string): void;
|
||||||
|
|
||||||
|
createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description
|
* @description
|
||||||
* Configures and initializes environment for unit testing and provides methods for
|
* Configures and initializes environment for unit testing and provides methods for
|
||||||
|
@ -30,7 +108,7 @@ let _nextRootElementId = 0;
|
||||||
* Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
|
* Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
|
||||||
* according to the compiler used.
|
* according to the compiler used.
|
||||||
*/
|
*/
|
||||||
export class TestBedViewEngine implements Injector {
|
export class TestBedViewEngine implements Injector, TestBed {
|
||||||
/**
|
/**
|
||||||
* Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
* Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
||||||
* angular module. These are common to every test in the suite.
|
* angular module. These are common to every test in the suite.
|
||||||
|
@ -59,27 +137,27 @@ export class TestBedViewEngine implements Injector {
|
||||||
*/
|
*/
|
||||||
static resetTestEnvironment(): void { _getTestBedViewEngine().resetTestEnvironment(); }
|
static resetTestEnvironment(): void { _getTestBedViewEngine().resetTestEnvironment(); }
|
||||||
|
|
||||||
static resetTestingModule(): typeof TestBed {
|
static resetTestingModule(): TestBedStatic {
|
||||||
_getTestBedViewEngine().resetTestingModule();
|
_getTestBedViewEngine().resetTestingModule();
|
||||||
return TestBed;
|
return TestBedViewEngine as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows overriding default compiler providers and settings
|
* Allows overriding default compiler providers and settings
|
||||||
* which are defined in test_injector.js
|
* which are defined in test_injector.js
|
||||||
*/
|
*/
|
||||||
static configureCompiler(config: {providers?: any[]; useJit?: boolean;}): typeof TestBed {
|
static configureCompiler(config: {providers?: any[]; useJit?: boolean;}): TestBedStatic {
|
||||||
_getTestBedViewEngine().configureCompiler(config);
|
_getTestBedViewEngine().configureCompiler(config);
|
||||||
return TestBed;
|
return TestBedViewEngine as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows overriding default providers, directives, pipes, modules of the test injector,
|
* Allows overriding default providers, directives, pipes, modules of the test injector,
|
||||||
* which are defined in test_injector.js
|
* which are defined in test_injector.js
|
||||||
*/
|
*/
|
||||||
static configureTestingModule(moduleDef: TestModuleMetadata): typeof TestBed {
|
static configureTestingModule(moduleDef: TestModuleMetadata): TestBedStatic {
|
||||||
_getTestBedViewEngine().configureTestingModule(moduleDef);
|
_getTestBedViewEngine().configureTestingModule(moduleDef);
|
||||||
return TestBed;
|
return TestBedViewEngine as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,31 +167,31 @@ export class TestBedViewEngine implements Injector {
|
||||||
*/
|
*/
|
||||||
static compileComponents(): Promise<any> { return getTestBed().compileComponents(); }
|
static compileComponents(): Promise<any> { return getTestBed().compileComponents(); }
|
||||||
|
|
||||||
static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): typeof TestBed {
|
static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic {
|
||||||
_getTestBedViewEngine().overrideModule(ngModule, override);
|
_getTestBedViewEngine().overrideModule(ngModule, override);
|
||||||
return TestBed;
|
return TestBedViewEngine as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
static overrideComponent(component: Type<any>, override: MetadataOverride<Component>):
|
static overrideComponent(component: Type<any>, override: MetadataOverride<Component>):
|
||||||
typeof TestBed {
|
TestBedStatic {
|
||||||
_getTestBedViewEngine().overrideComponent(component, override);
|
_getTestBedViewEngine().overrideComponent(component, override);
|
||||||
return TestBed;
|
return TestBedViewEngine as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>):
|
static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>):
|
||||||
typeof TestBed {
|
TestBedStatic {
|
||||||
_getTestBedViewEngine().overrideDirective(directive, override);
|
_getTestBedViewEngine().overrideDirective(directive, override);
|
||||||
return TestBed;
|
return TestBedViewEngine as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
static overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): typeof TestBed {
|
static overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBedStatic {
|
||||||
_getTestBedViewEngine().overridePipe(pipe, override);
|
_getTestBedViewEngine().overridePipe(pipe, override);
|
||||||
return TestBed;
|
return TestBedViewEngine as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
static overrideTemplate(component: Type<any>, template: string): typeof TestBed {
|
static overrideTemplate(component: Type<any>, template: string): TestBedStatic {
|
||||||
_getTestBedViewEngine().overrideComponent(component, {set: {template, templateUrl: null !}});
|
_getTestBedViewEngine().overrideComponent(component, {set: {template, templateUrl: null !}});
|
||||||
return TestBed;
|
return TestBedViewEngine as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -122,10 +200,9 @@ export class TestBedViewEngine implements Injector {
|
||||||
*
|
*
|
||||||
* Note: This works for JIT and AOTed components as well.
|
* Note: This works for JIT and AOTed components as well.
|
||||||
*/
|
*/
|
||||||
static overrideTemplateUsingTestingModule(component: Type<any>, template: string):
|
static overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBedStatic {
|
||||||
typeof TestBed {
|
|
||||||
_getTestBedViewEngine().overrideTemplateUsingTestingModule(component, template);
|
_getTestBedViewEngine().overrideTemplateUsingTestingModule(component, template);
|
||||||
return TestBed;
|
return TestBedViewEngine as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -136,15 +213,15 @@ export class TestBedViewEngine implements Injector {
|
||||||
static overrideProvider(token: any, provider: {
|
static overrideProvider(token: any, provider: {
|
||||||
useFactory: Function,
|
useFactory: Function,
|
||||||
deps: any[],
|
deps: any[],
|
||||||
}): typeof TestBed;
|
}): TestBedStatic;
|
||||||
static overrideProvider(token: any, provider: {useValue: any;}): typeof TestBed;
|
static overrideProvider(token: any, provider: {useValue: any;}): TestBedStatic;
|
||||||
static overrideProvider(token: any, provider: {
|
static overrideProvider(token: any, provider: {
|
||||||
useFactory?: Function,
|
useFactory?: Function,
|
||||||
useValue?: any,
|
useValue?: any,
|
||||||
deps?: any[],
|
deps?: any[],
|
||||||
}): typeof TestBed {
|
}): TestBedStatic {
|
||||||
_getTestBedViewEngine().overrideProvider(token, provider as any);
|
_getTestBedViewEngine().overrideProvider(token, provider as any);
|
||||||
return TestBed;
|
return TestBedViewEngine as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -161,9 +238,9 @@ export class TestBedViewEngine implements Injector {
|
||||||
useFactory?: Function,
|
useFactory?: Function,
|
||||||
useValue?: any,
|
useValue?: any,
|
||||||
deps?: any[],
|
deps?: any[],
|
||||||
}): typeof TestBed {
|
}): TestBedStatic {
|
||||||
_getTestBedViewEngine().deprecatedOverrideProvider(token, provider as any);
|
_getTestBedViewEngine().deprecatedOverrideProvider(token, provider as any);
|
||||||
return TestBed;
|
return TestBedViewEngine as any as TestBedStatic;
|
||||||
}
|
}
|
||||||
|
|
||||||
static get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND) {
|
static get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND) {
|
||||||
|
@ -559,7 +636,8 @@ export class TestBedViewEngine implements Injector {
|
||||||
* Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
|
* Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
|
||||||
* according to the compiler used.
|
* according to the compiler used.
|
||||||
*/
|
*/
|
||||||
export const TestBed = ivyEnabled ? TestBedRender3 : TestBedViewEngine;
|
export const TestBed: TestBedStatic =
|
||||||
|
ivyEnabled ? TestBedRender3 as any as TestBedStatic : TestBedViewEngine as any as TestBedStatic;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a singleton of the applicable `TestBed`.
|
* Returns a singleton of the applicable `TestBed`.
|
||||||
|
@ -568,8 +646,7 @@ export const TestBed = ivyEnabled ? TestBedRender3 : TestBedViewEngine;
|
||||||
*
|
*
|
||||||
* @experimental
|
* @experimental
|
||||||
*/
|
*/
|
||||||
export const getTestBed: () => TestBedRender3 | TestBedViewEngine =
|
export const getTestBed: () => TestBed = ivyEnabled ? _getTestBedRender3 : _getTestBedViewEngine;
|
||||||
ivyEnabled ? _getTestBedRender3 : _getTestBedViewEngine;
|
|
||||||
|
|
||||||
let testBed: TestBedViewEngine;
|
let testBed: TestBedViewEngine;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,11 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {InjectionToken, SchemaMetadata} from '@angular/core';
|
import {Component, Directive, InjectionToken, NgModule, Pipe, PlatformRef, SchemaMetadata, Type} from '@angular/core';
|
||||||
|
|
||||||
|
import {ComponentFixture} from './component_fixture';
|
||||||
|
import {MetadataOverride} from './metadata_override';
|
||||||
|
import {TestBed} from './test_bed';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An abstract class for inserting the root test component element in a platform independent way.
|
* An abstract class for inserting the root test component element in a platform independent way.
|
||||||
|
@ -38,3 +42,95 @@ export type TestModuleMetadata = {
|
||||||
schemas?: Array<SchemaMetadata|any[]>,
|
schemas?: Array<SchemaMetadata|any[]>,
|
||||||
aotSummaries?: () => any[],
|
aotSummaries?: () => any[],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Static methods implemented by the `TestBedViewEngine` and `TestBedRender3`
|
||||||
|
*/
|
||||||
|
export interface TestBedStatic {
|
||||||
|
new (...args: any[]): TestBed;
|
||||||
|
|
||||||
|
initTestEnvironment(
|
||||||
|
ngModule: Type<any>|Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reset the providers for the test injector.
|
||||||
|
*
|
||||||
|
* @experimental
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwrites all providers for the given token with the given provider definition.
|
||||||
|
*
|
||||||
|
* @deprecated as it makes all NgModules lazy. Introduced only for migrating off of it.
|
||||||
|
*/
|
||||||
|
deprecatedOverrideProvider(token: any, provider: {
|
||||||
|
useFactory: Function,
|
||||||
|
deps: any[],
|
||||||
|
}): void;
|
||||||
|
deprecatedOverrideProvider(token: any, provider: {useValue: any;}): void;
|
||||||
|
deprecatedOverrideProvider(token: any, provider: {
|
||||||
|
useFactory?: Function,
|
||||||
|
useValue?: any,
|
||||||
|
deps?: any[],
|
||||||
|
}): TestBedStatic;
|
||||||
|
|
||||||
|
get(token: any, notFoundValue?: any): any;
|
||||||
|
|
||||||
|
createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
||||||
|
}
|
||||||
|
|
|
@ -15,10 +15,9 @@
|
||||||
export * from './async';
|
export * from './async';
|
||||||
export * from './component_fixture';
|
export * from './component_fixture';
|
||||||
export * from './fake_async';
|
export * from './fake_async';
|
||||||
export * from './test_bed';
|
export {TestBed, getTestBed, inject, InjectSetupWrapper, withModule} from './test_bed';
|
||||||
export * from './test_bed_common';
|
export * from './test_bed_common';
|
||||||
export * from './r3_test_bed';
|
|
||||||
export * from './before_each';
|
export * from './before_each';
|
||||||
export * from './metadata_override';
|
export * from './metadata_override';
|
||||||
export * from './metadata_overrider';
|
export {MetadataOverrider as ɵMetadataOverrider} from './metadata_overrider';
|
||||||
export * from './private_export_testing';
|
export * from './private_export_testing';
|
||||||
|
|
|
@ -6,5 +6,5 @@
|
||||||
* found in the LICENSE file at https://angular.io/license
|
* found in the LICENSE file at https://angular.io/license
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// `MetadataOverrider` has been moved to core to allow using it from the render3 TestBed
|
// `MetadataOverrider` has been moved to core/testing to allow using it from the render3 TestBed
|
||||||
export {MetadataOverrider} from '@angular/core/testing';
|
export {ɵMetadataOverrider as MetadataOverrider} from '@angular/core/testing';
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
export declare function _getTestBedRender3(): TestBedRender3;
|
|
||||||
|
|
||||||
export declare function async(fn: Function): (done: any) => any;
|
export declare function async(fn: Function): (done: any) => any;
|
||||||
|
|
||||||
export declare class ComponentFixture<T> {
|
export declare class ComponentFixture<T> {
|
||||||
|
@ -39,7 +37,7 @@ export declare function flush(maxTurns?: number): number;
|
||||||
export declare function flushMicrotasks(): void;
|
export declare function flushMicrotasks(): void;
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare const getTestBed: () => TestBedRender3 | TestBedViewEngine;
|
export declare const getTestBed: () => TestBed;
|
||||||
|
|
||||||
export declare function inject(tokens: any[], fn: Function): () => any;
|
export declare function inject(tokens: any[], fn: Function): () => any;
|
||||||
|
|
||||||
|
@ -56,27 +54,25 @@ export declare type MetadataOverride<T> = {
|
||||||
set?: Partial<T>;
|
set?: Partial<T>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export declare class MetadataOverrider {
|
|
||||||
overrideMetadata<C extends T, T>(metadataClass: {
|
|
||||||
new (options: T): C;
|
|
||||||
}, oldMetadata: C, override: MetadataOverride<T>): C;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
export declare function resetFakeAsyncZone(): void;
|
export declare function resetFakeAsyncZone(): void;
|
||||||
|
|
||||||
export declare const TestBed: typeof TestBedRender3 | typeof TestBedViewEngine;
|
export declare const TestBed: TestBedStatic;
|
||||||
|
|
||||||
export declare class TestBedRender3 {
|
export interface TestBedStatic {
|
||||||
ngModule: Type<any> | Type<any>[];
|
new (...args: any[]): TestBed;
|
||||||
platform: PlatformRef;
|
|
||||||
compileComponents(): Promise<any>;
|
compileComponents(): Promise<any>;
|
||||||
configureCompiler(config: {
|
configureCompiler(config: {
|
||||||
providers?: any[];
|
providers?: any[];
|
||||||
useJit?: boolean;
|
useJit?: boolean;
|
||||||
}): void;
|
}): TestBedStatic;
|
||||||
configureTestingModule(moduleDef: TestModuleMetadata): void;
|
configureTestingModule(moduleDef: TestModuleMetadata): TestBedStatic;
|
||||||
createComponent<T>(type: Type<T>): ComponentFixture<T>;
|
createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
||||||
|
deprecatedOverrideProvider(token: any, provider: {
|
||||||
|
useFactory?: Function;
|
||||||
|
useValue?: any;
|
||||||
|
deps?: any[];
|
||||||
|
}): TestBedStatic;
|
||||||
deprecatedOverrideProvider(token: any, provider: {
|
deprecatedOverrideProvider(token: any, provider: {
|
||||||
useValue: any;
|
useValue: any;
|
||||||
}): void;
|
}): void;
|
||||||
|
@ -84,119 +80,28 @@ export declare class TestBedRender3 {
|
||||||
useFactory: Function;
|
useFactory: Function;
|
||||||
deps: any[];
|
deps: any[];
|
||||||
}): void;
|
}): void;
|
||||||
execute(tokens: any[], fn: Function, context?: any): any;
|
|
||||||
get(token: any, notFoundValue?: any): any;
|
get(token: any, notFoundValue?: any): any;
|
||||||
/** @experimental */ initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): void;
|
initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed;
|
||||||
overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void;
|
overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBedStatic;
|
||||||
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void;
|
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBedStatic;
|
||||||
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void;
|
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic;
|
||||||
overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): void;
|
overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBedStatic;
|
||||||
|
overrideProvider(token: any, provider: {
|
||||||
|
useValue: any;
|
||||||
|
}): TestBedStatic;
|
||||||
overrideProvider(token: any, provider: {
|
overrideProvider(token: any, provider: {
|
||||||
useFactory?: Function;
|
useFactory?: Function;
|
||||||
useValue?: any;
|
useValue?: any;
|
||||||
deps?: any[];
|
deps?: any[];
|
||||||
}): void;
|
}): TestBedStatic;
|
||||||
overrideTemplateUsingTestingModule(component: Type<any>, template: string): void;
|
|
||||||
/** @experimental */ resetTestEnvironment(): void;
|
|
||||||
resetTestingModule(): void;
|
|
||||||
static compileComponents(): Promise<any>;
|
|
||||||
static configureCompiler(config: {
|
|
||||||
providers?: any[];
|
|
||||||
useJit?: boolean;
|
|
||||||
}): typeof TestBedRender3;
|
|
||||||
static configureTestingModule(moduleDef: TestModuleMetadata): typeof TestBedRender3;
|
|
||||||
static createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
|
||||||
static deprecatedOverrideProvider(token: any, provider: {
|
|
||||||
useValue: any;
|
|
||||||
}): void;
|
|
||||||
/** @deprecated */ static deprecatedOverrideProvider(token: any, provider: {
|
|
||||||
useFactory: Function;
|
|
||||||
deps: any[];
|
|
||||||
}): void;
|
|
||||||
static get(token: any, notFoundValue?: any): any;
|
|
||||||
/** @experimental */ static initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBedRender3;
|
|
||||||
static overrideComponent(component: Type<any>, override: MetadataOverride<Component>): typeof TestBedRender3;
|
|
||||||
static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): typeof TestBedRender3;
|
|
||||||
static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): typeof TestBedRender3;
|
|
||||||
static overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): typeof TestBedRender3;
|
|
||||||
static overrideProvider(token: any, provider: {
|
|
||||||
useFactory: Function;
|
|
||||||
deps: any[];
|
|
||||||
}): typeof TestBedRender3;
|
|
||||||
static overrideProvider(token: any, provider: {
|
|
||||||
useValue: any;
|
|
||||||
}): typeof TestBedRender3;
|
|
||||||
static overrideTemplate(component: Type<any>, template: string): typeof TestBedRender3;
|
|
||||||
static overrideTemplateUsingTestingModule(component: Type<any>, template: string): typeof TestBedRender3;
|
|
||||||
/** @experimental */ static resetTestEnvironment(): void;
|
|
||||||
static resetTestingModule(): typeof TestBedRender3;
|
|
||||||
}
|
|
||||||
|
|
||||||
export declare class TestBedViewEngine implements Injector {
|
|
||||||
ngModule: Type<any> | Type<any>[];
|
|
||||||
platform: PlatformRef;
|
|
||||||
compileComponents(): Promise<any>;
|
|
||||||
configureCompiler(config: {
|
|
||||||
providers?: any[];
|
|
||||||
useJit?: boolean;
|
|
||||||
}): void;
|
|
||||||
configureTestingModule(moduleDef: TestModuleMetadata): void;
|
|
||||||
createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
|
||||||
/** @deprecated */ deprecatedOverrideProvider(token: any, provider: {
|
|
||||||
useFactory: Function;
|
|
||||||
deps: any[];
|
|
||||||
}): void;
|
|
||||||
deprecatedOverrideProvider(token: any, provider: {
|
|
||||||
useValue: any;
|
|
||||||
}): void;
|
|
||||||
execute(tokens: any[], fn: Function, context?: any): any;
|
|
||||||
get(token: any, notFoundValue?: any): any;
|
|
||||||
/** @experimental */ initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): void;
|
|
||||||
overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void;
|
|
||||||
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void;
|
|
||||||
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void;
|
|
||||||
overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): void;
|
|
||||||
overrideProvider(token: any, provider: {
|
overrideProvider(token: any, provider: {
|
||||||
useFactory: Function;
|
useFactory: Function;
|
||||||
deps: any[];
|
deps: any[];
|
||||||
}): void;
|
}): TestBedStatic;
|
||||||
overrideProvider(token: any, provider: {
|
overrideTemplate(component: Type<any>, template: string): TestBedStatic;
|
||||||
useValue: any;
|
overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBedStatic;
|
||||||
}): void;
|
|
||||||
overrideTemplateUsingTestingModule(component: Type<any>, template: string): void;
|
|
||||||
/** @experimental */ resetTestEnvironment(): void;
|
/** @experimental */ resetTestEnvironment(): void;
|
||||||
resetTestingModule(): void;
|
resetTestingModule(): TestBedStatic;
|
||||||
static compileComponents(): Promise<any>;
|
|
||||||
static configureCompiler(config: {
|
|
||||||
providers?: any[];
|
|
||||||
useJit?: boolean;
|
|
||||||
}): typeof TestBed;
|
|
||||||
static configureTestingModule(moduleDef: TestModuleMetadata): typeof TestBed;
|
|
||||||
static createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
|
||||||
static deprecatedOverrideProvider(token: any, provider: {
|
|
||||||
useValue: any;
|
|
||||||
}): void;
|
|
||||||
/** @deprecated */ static deprecatedOverrideProvider(token: any, provider: {
|
|
||||||
useFactory: Function;
|
|
||||||
deps: any[];
|
|
||||||
}): void;
|
|
||||||
static get(token: any, notFoundValue?: any): any;
|
|
||||||
/** @experimental */ static initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBedViewEngine;
|
|
||||||
static overrideComponent(component: Type<any>, override: MetadataOverride<Component>): typeof TestBed;
|
|
||||||
static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): typeof TestBed;
|
|
||||||
static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): typeof TestBed;
|
|
||||||
static overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): typeof TestBed;
|
|
||||||
static overrideProvider(token: any, provider: {
|
|
||||||
useValue: any;
|
|
||||||
}): typeof TestBed;
|
|
||||||
static overrideProvider(token: any, provider: {
|
|
||||||
useFactory: Function;
|
|
||||||
deps: any[];
|
|
||||||
}): typeof TestBed;
|
|
||||||
static overrideTemplate(component: Type<any>, template: string): typeof TestBed;
|
|
||||||
static overrideTemplateUsingTestingModule(component: Type<any>, template: string): typeof TestBed;
|
|
||||||
/** @experimental */ static resetTestEnvironment(): void;
|
|
||||||
static resetTestingModule(): typeof TestBed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @experimental */
|
/** @experimental */
|
||||||
|
|
Loading…
Reference in New Issue