angular/goldens/public-api/core/testing/index.api.md
Andrew Scott f7918f5272 feat(core): Add 'flush' parameter option to fakeAsync to flush after the test (#57239)
From the internal issue on the matter:

> When using the standard Jasmine version of it promises returned by the body function are automatically awaited. The Catalyst version of it is fake-async, so awaiting the promise does not make sense; however it would be nice if Catalyst automatically flushed the promise to replicate the experience of using standard it. This would allow users to do the following:

```
it('should fail later', async () => {
  await new Promise(r => setTimeout(r));
  fail('failure');
});
```
> In Catalyst today the above test will pass. If this proposal to automatically flush the resulting promise were implemented it would fail.

Flushing after the tests complete has been the default behavior inside
Google since 2020. Very few tests remain that use the old behavior of
only flushing microtasks. The example above would actually fail with
`fakeAsync` due to the pending timer, but the argument still remains the
same. We might as well just flush if we're going to fail the test
anyways by throwing if there's no flush at the end.

PR Close #57239
2024-08-05 17:46:04 +00:00

7.3 KiB

API Report File for "@angular/core_testing"

Do not edit this file. It is a report generated by API Extractor.


import { ChangeDetectorRef } from '@angular/core';
import { Component } from '@angular/core';
import { ComponentRef } from '@angular/core';
import { DebugElement } from '@angular/core';
import { ɵDeferBlockBehavior as DeferBlockBehavior } from '@angular/core';
import { ɵDeferBlockState as DeferBlockState } from '@angular/core';
import { Directive } from '@angular/core';
import { ElementRef } from '@angular/core';
import { InjectFlags } from '@angular/core';
import { InjectionToken } from '@angular/core';
import { InjectOptions } from '@angular/core';
import { NgModule } from '@angular/core';
import { NgZone } from '@angular/core';
import { Pipe } from '@angular/core';
import { PlatformRef } from '@angular/core';
import { ProviderToken } from '@angular/core';
import { SchemaMetadata } from '@angular/core';
import { Type } from '@angular/core';
import { ɵDeferBlockDetails } from '@angular/core';

// @public
export const __core_private_testing_placeholder__ = "";

// @public
export abstract class ComponentFixture<T> {
    constructor(componentRef: ComponentRef<T>);
    abstract autoDetectChanges(autoDetect?: boolean): void;
    changeDetectorRef: ChangeDetectorRef;
    checkNoChanges(): void;
    componentInstance: T;
    // (undocumented)
    componentRef: ComponentRef<T>;
    debugElement: DebugElement;
    destroy(): void;
    abstract detectChanges(checkNoChanges?: boolean): void;
    elementRef: ElementRef;
    getDeferBlocks(): Promise<DeferBlockFixture[]>;
    isStable(): boolean;
    nativeElement: any;
    // (undocumented)
    ngZone: NgZone | null;
    whenRenderingDone(): Promise<any>;
    whenStable(): Promise<any>;
}

// @public (undocumented)
export const ComponentFixtureAutoDetect: InjectionToken<boolean>;

// @public (undocumented)
export const ComponentFixtureNoNgZone: InjectionToken<boolean>;

export { DeferBlockBehavior }

// @public
export class DeferBlockFixture {
    constructor(block: ɵDeferBlockDetails, componentFixture: ComponentFixture<unknown>);
    getDeferBlocks(): Promise<DeferBlockFixture[]>;
    render(state: DeferBlockState): Promise<void>;
}

export { DeferBlockState }

// @public
export function discardPeriodicTasks(): void;

// @public
export function fakeAsync(fn: Function, options?: {
    flush?: boolean;
}): (...args: any[]) => any;

// @public
export function flush(maxTurns?: number): number;

// @public
export function flushMicrotasks(): void;

// @public
export function getTestBed(): TestBed;

// @public
export function inject(tokens: any[], fn: Function): () => any;

// @public (undocumented)
export class InjectSetupWrapper {
    constructor(_moduleDef: () => TestModuleMetadata);
    // (undocumented)
    inject(tokens: any[], fn: Function): () => any;
}

// @public
export type MetadataOverride<T> = {
    add?: Partial<T>;
    remove?: Partial<T>;
    set?: Partial<T>;
};

// @public
export interface ModuleTeardownOptions {
    destroyAfterEach: boolean;
    rethrowErrors?: boolean;
}

// @public
export function resetFakeAsyncZone(): void;

// @public (undocumented)
export interface TestBed {
    // (undocumented)
    compileComponents(): Promise<any>;
    // (undocumented)
    configureCompiler(config: {
        providers?: any[];
        useJit?: boolean;
    }): void;
    // (undocumented)
    configureTestingModule(moduleDef: TestModuleMetadata): TestBed;
    // (undocumented)
    createComponent<T>(component: Type<T>): ComponentFixture<T>;
    // (undocumented)
    execute(tokens: any[], fn: Function, context?: any): any;
    flushEffects(): void;
    // @deprecated (undocumented)
    get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
    // @deprecated (undocumented)
    get(token: any, notFoundValue?: any): any;
    initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, options?: TestEnvironmentOptions): void;
    // (undocumented)
    inject<T>(token: ProviderToken<T>, notFoundValue: undefined, options: InjectOptions & {
        optional?: false;
    }): T;
    // (undocumented)
    inject<T>(token: ProviderToken<T>, notFoundValue: null | undefined, options: InjectOptions): T | null;
    // (undocumented)
    inject<T>(token: ProviderToken<T>, notFoundValue?: T, options?: InjectOptions): T;
    // @deprecated (undocumented)
    inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
    // @deprecated (undocumented)
    inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T | null;
    // (undocumented)
    get ngModule(): Type<any> | Type<any>[];
    // (undocumented)
    overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBed;
    // (undocumented)
    overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBed;
    // (undocumented)
    overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBed;
    // (undocumented)
    overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBed;
    overrideProvider(token: any, provider: {
        useFactory: Function;
        deps: any[];
        multi?: boolean;
    }): TestBed;
    // (undocumented)
    overrideProvider(token: any, provider: {
        useValue: any;
        multi?: boolean;
    }): TestBed;
    // (undocumented)
    overrideProvider(token: any, provider: {
        useFactory?: Function;
        useValue?: any;
        deps?: any[];
        multi?: boolean;
    }): TestBed;
    // (undocumented)
    overrideTemplate(component: Type<any>, template: string): TestBed;
    // (undocumented)
    overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBed;
    // (undocumented)
    get platform(): PlatformRef;
    resetTestEnvironment(): void;
    // (undocumented)
    resetTestingModule(): TestBed;
    runInInjectionContext<T>(fn: () => T): T;
}

// @public
export const TestBed: TestBedStatic;

// @public
export interface TestBedStatic extends TestBed {
    // (undocumented)
    new (...args: any[]): TestBed;
}

// @public
export class TestComponentRenderer {
    // (undocumented)
    insertRootElement(rootElementId: string): void;
    // (undocumented)
    removeAllRootElements?(): void;
}

// @public (undocumented)
export interface TestEnvironmentOptions {
    errorOnUnknownElements?: boolean;
    errorOnUnknownProperties?: boolean;
    teardown?: ModuleTeardownOptions;
}

// @public (undocumented)
export interface TestModuleMetadata {
    // (undocumented)
    declarations?: any[];
    deferBlockBehavior?: DeferBlockBehavior;
    errorOnUnknownElements?: boolean;
    errorOnUnknownProperties?: boolean;
    // (undocumented)
    imports?: any[];
    // (undocumented)
    providers?: any[];
    // (undocumented)
    schemas?: Array<SchemaMetadata | any[]>;
    // (undocumented)
    teardown?: ModuleTeardownOptions;
}

// @public
export function tick(millis?: number, tickOptions?: {
    processNewMacroTasksSynchronously: boolean;
}): void;

// @public
export function waitForAsync(fn: Function): (done: any) => any;

// @public (undocumented)
export function withModule(moduleDef: TestModuleMetadata): InjectSetupWrapper;

// @public (undocumented)
export function withModule(moduleDef: TestModuleMetadata, fn: Function): () => any;

// (No @packageDocumentation comment for this package)