fix(testing): add an explicit doAsyncPrecompilation step (#10015)
This removes the magic from the `inject` test helper that would inspect the current zone and would only work with our `async` test helper. Now, `inject` is always synchronous, and if you are using a module that requires async precompilation, you're required to call `doAsyncPrecompilation` in your tests. This is part of the breaking changes introduced with the swap to each test having an AppModule. Closes #9975 Closes #9593 BREAKING CHANGE: `TestInjector` is now renamed to `TestBed` Before: ```js import {TestInjector, getTestInjector} from '@angular/core/testing'; ``` After: ```js import {TestBed, getTestBed} from '@angular/core/testing'; ```
This commit is contained in:
52
tools/public_api_guard/core/testing.d.ts
vendored
52
tools/public_api_guard/core/testing.d.ts
vendored
@ -46,6 +46,9 @@ export declare function configureModule(moduleDef: {
|
||||
/** @experimental */
|
||||
export declare function discardPeriodicTasks(): void;
|
||||
|
||||
/** @experimental */
|
||||
export declare function doAsyncPrecompilation(): Promise<any>;
|
||||
|
||||
/** @experimental */
|
||||
export declare function fakeAsync(fn: Function): (...args: any[]) => any;
|
||||
|
||||
@ -53,7 +56,10 @@ export declare function fakeAsync(fn: Function): (...args: any[]) => any;
|
||||
export declare function flushMicrotasks(): void;
|
||||
|
||||
/** @experimental */
|
||||
export declare function getTestInjector(): TestInjector;
|
||||
export declare function getTestBed(): TestBed;
|
||||
|
||||
/** @deprecated */
|
||||
export declare function getTestInjector(): TestBed;
|
||||
|
||||
/** @experimental */
|
||||
export declare function initTestEnvironment(appModule: Type, platform: PlatformRef): void;
|
||||
@ -82,6 +88,28 @@ export declare function resetTestEnvironment(): void;
|
||||
/** @deprecated */
|
||||
export declare function setBaseTestProviders(platformProviders: Array<Type | Provider | any[]>, applicationProviders: Array<Type | Provider | any[]>): void;
|
||||
|
||||
/** @experimental */
|
||||
export declare class TestBed implements Injector {
|
||||
appModule: Type;
|
||||
platform: PlatformRef;
|
||||
configureCompiler(config: {
|
||||
providers?: any[];
|
||||
useJit?: boolean;
|
||||
}): void;
|
||||
configureModule(moduleDef: {
|
||||
providers?: any[];
|
||||
directives?: any[];
|
||||
pipes?: any[];
|
||||
precompile?: any[];
|
||||
modules?: any[];
|
||||
}): void;
|
||||
createAppModuleFactory(): Promise<AppModuleFactory<any>>;
|
||||
execute(tokens: any[], fn: Function): any;
|
||||
get(token: any, notFoundValue?: any): any;
|
||||
initTestAppModule(): void;
|
||||
reset(): void;
|
||||
}
|
||||
|
||||
/** @stable */
|
||||
export declare class TestComponentBuilder {
|
||||
protected _injector: Injector;
|
||||
@ -103,28 +131,6 @@ export declare class TestComponentRenderer {
|
||||
insertRootElement(rootElementId: string): void;
|
||||
}
|
||||
|
||||
/** @experimental */
|
||||
export declare class TestInjector implements Injector {
|
||||
appModule: Type;
|
||||
platform: PlatformRef;
|
||||
configureCompiler(config: {
|
||||
providers?: any[];
|
||||
useJit?: boolean;
|
||||
}): void;
|
||||
configureModule(moduleDef: {
|
||||
providers?: any[];
|
||||
directives?: any[];
|
||||
pipes?: any[];
|
||||
precompile?: any[];
|
||||
modules?: any[];
|
||||
}): void;
|
||||
createInjectorAsync(): Promise<Injector>;
|
||||
createInjectorSync(): Injector;
|
||||
execute(tokens: any[], fn: Function): any;
|
||||
get(token: any, notFoundValue?: any): any;
|
||||
reset(): void;
|
||||
}
|
||||
|
||||
/** @experimental */
|
||||
export declare function tick(millis?: number): void;
|
||||
|
||||
|
Reference in New Issue
Block a user