refactor(compiler): introduce `TestBed.deprecatedOverrideProvider` (#19558)
This allows use to fix `TestBed.overrideProvider` to keep imported `NgModule`s eager, while allowing our users to still keep the old semantics until they have fixed their tests. PR Close #19558
This commit is contained in:
parent
6ade68cff1
commit
931cf78057
|
@ -159,6 +159,25 @@ export class TestBed implements Injector {
|
||||||
return TestBed;
|
return TestBed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
static deprecatedOverrideProvider(token: any, provider: {
|
||||||
|
useFactory: Function,
|
||||||
|
deps: any[],
|
||||||
|
}): void;
|
||||||
|
static deprecatedOverrideProvider(token: any, provider: {useValue: any;}): void;
|
||||||
|
static deprecatedOverrideProvider(token: any, provider: {
|
||||||
|
useFactory?: Function,
|
||||||
|
useValue?: any,
|
||||||
|
deps?: any[],
|
||||||
|
}): typeof TestBed {
|
||||||
|
getTestBed().deprecatedOverrideProvider(token, provider as any);
|
||||||
|
return TestBed;
|
||||||
|
}
|
||||||
|
|
||||||
static get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND) {
|
static get(token: any, notFoundValue: any = Injector.THROW_IF_NOT_FOUND) {
|
||||||
return getTestBed().get(token, notFoundValue);
|
return getTestBed().get(token, notFoundValue);
|
||||||
}
|
}
|
||||||
|
@ -394,11 +413,33 @@ export class TestBed implements Injector {
|
||||||
deps: any[],
|
deps: any[],
|
||||||
}): void;
|
}): void;
|
||||||
overrideProvider(token: any, provider: {useValue: any;}): void;
|
overrideProvider(token: any, provider: {useValue: any;}): void;
|
||||||
overrideProvider(token: any, provider: {
|
overrideProvider(token: any, provider: {useFactory?: Function, useValue?: any, deps?: any[]}):
|
||||||
|
void {
|
||||||
|
this.overrideProviderImpl(token, provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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 {
|
||||||
|
this.overrideProviderImpl(token, provider, /* deprecated */ true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private overrideProviderImpl(
|
||||||
|
token: any, provider: {
|
||||||
useFactory?: Function,
|
useFactory?: Function,
|
||||||
useValue?: any,
|
useValue?: any,
|
||||||
deps?: any[],
|
deps?: any[],
|
||||||
}): void {
|
},
|
||||||
|
deprecated = false): void {
|
||||||
let flags: NodeFlags = 0;
|
let flags: NodeFlags = 0;
|
||||||
let value: any;
|
let value: any;
|
||||||
if (provider.useFactory) {
|
if (provider.useFactory) {
|
||||||
|
|
|
@ -71,6 +71,13 @@ export declare class TestBed implements Injector {
|
||||||
}): void;
|
}): void;
|
||||||
configureTestingModule(moduleDef: TestModuleMetadata): void;
|
configureTestingModule(moduleDef: TestModuleMetadata): void;
|
||||||
createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
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;
|
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;
|
/** @experimental */ initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): void;
|
||||||
|
@ -94,6 +101,13 @@ export declare class TestBed implements Injector {
|
||||||
}): typeof TestBed;
|
}): typeof TestBed;
|
||||||
static configureTestingModule(moduleDef: TestModuleMetadata): typeof TestBed;
|
static configureTestingModule(moduleDef: TestModuleMetadata): typeof TestBed;
|
||||||
static createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
static createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
||||||
|
/** @deprecated */ static deprecatedOverrideProvider(token: any, provider: {
|
||||||
|
useFactory: Function;
|
||||||
|
deps: any[];
|
||||||
|
}): void;
|
||||||
|
static deprecatedOverrideProvider(token: any, provider: {
|
||||||
|
useValue: any;
|
||||||
|
}): void;
|
||||||
static get(token: any, notFoundValue?: any): any;
|
static get(token: any, notFoundValue?: any): any;
|
||||||
/** @experimental */ static initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed;
|
/** @experimental */ static initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed;
|
||||||
static overrideComponent(component: Type<any>, override: MetadataOverride<Component>): typeof TestBed;
|
static overrideComponent(component: Type<any>, override: MetadataOverride<Component>): typeof TestBed;
|
||||||
|
|
Loading…
Reference in New Issue