123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514 |
- /**
- * @license Angular v16.2.9
- * (c) 2010-2022 Google LLC. https://angular.io/
- * License: MIT
- */
- import { ChangeDetectorRef } from '@angular/core';
- import { Component } from '@angular/core';
- import { ComponentRef } from '@angular/core';
- import { DebugElement } 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';
- /**
- * This API should be removed. But doing so seems to break `google3` and so it requires a bit of
- * investigation.
- *
- * A work around is to mark it as `@codeGenApi` for now and investigate later.
- *
- * @codeGenApi
- */
- export declare const __core_private_testing_placeholder__ = "";
- /**
- * @deprecated use `waitForAsync()`, (expected removal in v12)
- * @see {@link waitForAsync}
- * @publicApi
- * */
- export declare function async(fn: Function): (done: any) => any;
- /**
- * Fixture for debugging and testing a component.
- *
- * @publicApi
- */
- export declare class ComponentFixture<T> {
- componentRef: ComponentRef<T>;
- ngZone: NgZone | null;
- private _autoDetect;
- /**
- * The DebugElement associated with the root element of this component.
- */
- debugElement: DebugElement;
- /**
- * The instance of the root component class.
- */
- componentInstance: T;
- /**
- * The native element at the root of the component.
- */
- nativeElement: any;
- /**
- * The ElementRef for the element at the root of the component.
- */
- elementRef: ElementRef;
- /**
- * The ChangeDetectorRef for the component
- */
- changeDetectorRef: ChangeDetectorRef;
- private _renderer;
- private _isStable;
- private _isDestroyed;
- private _resolve;
- private _promise;
- private _onUnstableSubscription;
- private _onStableSubscription;
- private _onMicrotaskEmptySubscription;
- private _onErrorSubscription;
- constructor(componentRef: ComponentRef<T>, ngZone: NgZone | null, _autoDetect: boolean);
- private _tick;
- /**
- * Trigger a change detection cycle for the component.
- */
- detectChanges(checkNoChanges?: boolean): void;
- /**
- * Do a change detection run to make sure there were no changes.
- */
- checkNoChanges(): void;
- /**
- * Set whether the fixture should autodetect changes.
- *
- * Also runs detectChanges once so that any existing change is detected.
- */
- autoDetectChanges(autoDetect?: boolean): void;
- /**
- * Return whether the fixture is currently stable or has async tasks that have not been completed
- * yet.
- */
- isStable(): boolean;
- /**
- * Get a promise that resolves when the fixture is stable.
- *
- * This can be used to resume testing after events have triggered asynchronous activity or
- * asynchronous change detection.
- */
- whenStable(): Promise<any>;
- private _getRenderer;
- /**
- * Get a promise that resolves when the ui state is stable following animations.
- */
- whenRenderingDone(): Promise<any>;
- /**
- * Trigger component destruction.
- */
- destroy(): void;
- }
- /**
- * @publicApi
- */
- export declare const ComponentFixtureAutoDetect: InjectionToken<boolean>;
- /**
- * @publicApi
- */
- export declare const ComponentFixtureNoNgZone: InjectionToken<boolean>;
- /**
- * Discard all remaining periodic tasks.
- *
- * @publicApi
- */
- export declare function discardPeriodicTasks(): void;
- /**
- * Wraps a function to be executed in the `fakeAsync` zone:
- * - Microtasks are manually executed by calling `flushMicrotasks()`.
- * - Timers are synchronous; `tick()` simulates the asynchronous passage of time.
- *
- * If there are any pending timers at the end of the function, an exception is thrown.
- *
- * Can be used to wrap `inject()` calls.
- *
- * @param fn The function that you want to wrap in the `fakeAsync` zone.
- *
- * @usageNotes
- * ### Example
- *
- * {@example core/testing/ts/fake_async.ts region='basic'}
- *
- *
- * @returns The function wrapped to be executed in the `fakeAsync` zone.
- * Any arguments passed when calling this returned function will be passed through to the `fn`
- * function in the parameters when it is called.
- *
- * @publicApi
- */
- export declare function fakeAsync(fn: Function): (...args: any[]) => any;
- /**
- * Flushes any pending microtasks and simulates the asynchronous passage of time for the timers in
- * the `fakeAsync` zone by
- * draining the macrotask queue until it is empty.
- *
- * @param maxTurns The maximum number of times the scheduler attempts to clear its queue before
- * throwing an error.
- * @returns The simulated time elapsed, in milliseconds.
- *
- * @publicApi
- */
- export declare function flush(maxTurns?: number): number;
- /**
- * Flush any pending microtasks.
- *
- * @publicApi
- */
- export declare function flushMicrotasks(): void;
- /**
- * Returns a singleton of the `TestBed` class.
- *
- * @publicApi
- */
- export declare function getTestBed(): TestBed;
- /**
- * Allows injecting dependencies in `beforeEach()` and `it()`. Note: this function
- * (imported from the `@angular/core/testing` package) can **only** be used to inject dependencies
- * in tests. To inject dependencies in your application code, use the [`inject`](api/core/inject)
- * function from the `@angular/core` package instead.
- *
- * Example:
- *
- * ```
- * beforeEach(inject([Dependency, AClass], (dep, object) => {
- * // some code that uses `dep` and `object`
- * // ...
- * }));
- *
- * it('...', inject([AClass], (object) => {
- * object.doSomething();
- * expect(...);
- * })
- * ```
- *
- * @publicApi
- */
- export declare function inject(tokens: any[], fn: Function): () => any;
- /**
- * @publicApi
- */
- export declare class InjectSetupWrapper {
- private _moduleDef;
- constructor(_moduleDef: () => TestModuleMetadata);
- private _addModule;
- inject(tokens: any[], fn: Function): () => any;
- }
- /**
- * Type used for modifications to metadata
- *
- * @publicApi
- */
- export declare type MetadataOverride<T> = {
- add?: Partial<T>;
- remove?: Partial<T>;
- set?: Partial<T>;
- };
- /**
- * Configures the test module teardown behavior in `TestBed`.
- * @publicApi
- */
- export declare interface ModuleTeardownOptions {
- /** Whether the test module should be destroyed after every test. Defaults to `true`. */
- destroyAfterEach: boolean;
- /** Whether errors during test module destruction should be re-thrown. Defaults to `true`. */
- rethrowErrors?: boolean;
- }
- /**
- * Clears out the shared fake async zone for a test.
- * To be called in a global `beforeEach`.
- *
- * @publicApi
- */
- export declare function resetFakeAsyncZone(): void;
- /**
- * @publicApi
- */
- export declare interface TestBed {
- get platform(): PlatformRef;
- get 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'.
- */
- initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, options?: TestEnvironmentOptions): void;
- /**
- * Reset the providers for the test injector.
- */
- resetTestEnvironment(): void;
- resetTestingModule(): TestBed;
- configureCompiler(config: {
- providers?: any[];
- useJit?: boolean;
- }): void;
- configureTestingModule(moduleDef: TestModuleMetadata): TestBed;
- compileComponents(): Promise<any>;
- inject<T>(token: ProviderToken<T>, notFoundValue: undefined, options: InjectOptions & {
- optional?: false;
- }): T;
- inject<T>(token: ProviderToken<T>, notFoundValue: null | undefined, options: InjectOptions): T | null;
- inject<T>(token: ProviderToken<T>, notFoundValue?: T, options?: InjectOptions): T;
- /** @deprecated use object-based flags (`InjectOptions`) instead. */
- inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
- /** @deprecated use object-based flags (`InjectOptions`) instead. */
- 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;
- /**
- * Runs the given function in the `EnvironmentInjector` context of `TestBed`.
- *
- * @see {@link EnvironmentInjector#runInContext}
- */
- runInInjectionContext<T>(fn: () => T): T;
- execute(tokens: any[], fn: Function, context?: any): any;
- overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBed;
- overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBed;
- overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBed;
- overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBed;
- overrideTemplate(component: Type<any>, template: string): TestBed;
- /**
- * Overwrites all providers for the given token with the given provider definition.
- */
- overrideProvider(token: any, provider: {
- useFactory: Function;
- deps: any[];
- multi?: boolean;
- }): TestBed;
- overrideProvider(token: any, provider: {
- useValue: any;
- multi?: boolean;
- }): TestBed;
- overrideProvider(token: any, provider: {
- useFactory?: Function;
- useValue?: any;
- deps?: any[];
- multi?: boolean;
- }): TestBed;
- overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBed;
- createComponent<T>(component: Type<T>): ComponentFixture<T>;
- }
- /**
- * @description
- * Configures and initializes environment for unit testing and provides methods for
- * creating components and services in unit tests.
- *
- * `TestBed` is the primary api for writing unit tests for Angular applications and libraries.
- *
- * @publicApi
- */
- export declare const TestBed: TestBedStatic;
- /**
- * Static methods implemented by the `TestBed`.
- *
- * @publicApi
- */
- export declare interface TestBedStatic extends TestBed {
- new (...args: any[]): TestBed;
- }
- /**
- * An abstract class for inserting the root test component element in a platform independent way.
- *
- * @publicApi
- */
- export declare class TestComponentRenderer {
- insertRootElement(rootElementId: string): void;
- removeAllRootElements?(): void;
- }
- /**
- * @publicApi
- */
- export declare interface TestEnvironmentOptions {
- /**
- * Configures the test module teardown behavior in `TestBed`.
- */
- teardown?: ModuleTeardownOptions;
- /**
- * Whether errors should be thrown when unknown elements are present in component's template.
- * Defaults to `false`, where the error is simply logged.
- * If set to `true`, the error is thrown.
- * @see [NG8001](/errors/NG8001) for the description of the error and how to fix it
- */
- errorOnUnknownElements?: boolean;
- /**
- * Whether errors should be thrown when unknown properties are present in component's template.
- * Defaults to `false`, where the error is simply logged.
- * If set to `true`, the error is thrown.
- * @see [NG8002](/errors/NG8002) for the description of the error and how to fix it
- */
- errorOnUnknownProperties?: boolean;
- }
- /**
- * @publicApi
- */
- export declare interface TestModuleMetadata {
- providers?: any[];
- declarations?: any[];
- imports?: any[];
- schemas?: Array<SchemaMetadata | any[]>;
- teardown?: ModuleTeardownOptions;
- /**
- * Whether NG0304 runtime errors should be thrown when unknown elements are present in component's
- * template. Defaults to `false`, where the error is simply logged. If set to `true`, the error is
- * thrown.
- * @see [NG8001](/errors/NG8001) for the description of the problem and how to fix it
- */
- errorOnUnknownElements?: boolean;
- /**
- * Whether errors should be thrown when unknown properties are present in component's template.
- * Defaults to `false`, where the error is simply logged.
- * If set to `true`, the error is thrown.
- * @see [NG8002](/errors/NG8002) for the description of the error and how to fix it
- */
- errorOnUnknownProperties?: boolean;
- }
- /**
- * Simulates the asynchronous passage of time for the timers in the `fakeAsync` zone.
- *
- * The microtasks queue is drained at the very start of this function and after any timer callback
- * has been executed.
- *
- * @param millis The number of milliseconds to advance the virtual timer.
- * @param tickOptions The options to pass to the `tick()` function.
- *
- * @usageNotes
- *
- * The `tick()` option is a flag called `processNewMacroTasksSynchronously`,
- * which determines whether or not to invoke new macroTasks.
- *
- * If you provide a `tickOptions` object, but do not specify a
- * `processNewMacroTasksSynchronously` property (`tick(100, {})`),
- * then `processNewMacroTasksSynchronously` defaults to true.
- *
- * If you omit the `tickOptions` parameter (`tick(100))`), then
- * `tickOptions` defaults to `{processNewMacroTasksSynchronously: true}`.
- *
- * ### Example
- *
- * {@example core/testing/ts/fake_async.ts region='basic'}
- *
- * The following example includes a nested timeout (new macroTask), and
- * the `tickOptions` parameter is allowed to default. In this case,
- * `processNewMacroTasksSynchronously` defaults to true, and the nested
- * function is executed on each tick.
- *
- * ```
- * it ('test with nested setTimeout', fakeAsync(() => {
- * let nestedTimeoutInvoked = false;
- * function funcWithNestedTimeout() {
- * setTimeout(() => {
- * nestedTimeoutInvoked = true;
- * });
- * };
- * setTimeout(funcWithNestedTimeout);
- * tick();
- * expect(nestedTimeoutInvoked).toBe(true);
- * }));
- * ```
- *
- * In the following case, `processNewMacroTasksSynchronously` is explicitly
- * set to false, so the nested timeout function is not invoked.
- *
- * ```
- * it ('test with nested setTimeout', fakeAsync(() => {
- * let nestedTimeoutInvoked = false;
- * function funcWithNestedTimeout() {
- * setTimeout(() => {
- * nestedTimeoutInvoked = true;
- * });
- * };
- * setTimeout(funcWithNestedTimeout);
- * tick(0, {processNewMacroTasksSynchronously: false});
- * expect(nestedTimeoutInvoked).toBe(false);
- * }));
- * ```
- *
- *
- * @publicApi
- */
- export declare function tick(millis?: number, tickOptions?: {
- processNewMacroTasksSynchronously: boolean;
- }): void;
- /**
- * Wraps a test function in an asynchronous test zone. The test will automatically
- * complete when all asynchronous calls within this zone are done. Can be used
- * to wrap an {@link inject} call.
- *
- * Example:
- *
- * ```
- * it('...', waitForAsync(inject([AClass], (object) => {
- * object.doSomething.then(() => {
- * expect(...);
- * })
- * });
- * ```
- *
- * @publicApi
- */
- export declare function waitForAsync(fn: Function): (done: any) => any;
- /**
- * @publicApi
- */
- export declare function withModule(moduleDef: TestModuleMetadata): InjectSetupWrapper;
- export declare function withModule(moduleDef: TestModuleMetadata, fn: Function): () => any;
- export declare class ɵMetadataOverrider {
- private _references;
- /**
- * Creates a new instance for the given metadata class
- * based on an old instance and overrides.
- */
- overrideMetadata<C extends T, T>(metadataClass: {
- new (options: T): C;
- }, oldMetadata: C, override: MetadataOverride<T>): C;
- }
- export { }
|