1 | /**
|
---|
2 | * @license Angular v12.2.13
|
---|
3 | * (c) 2010-2021 Google LLC. https://angular.io/
|
---|
4 | * License: MIT
|
---|
5 | */
|
---|
6 |
|
---|
7 | import { ChangeDetectorRef } from '@angular/core';
|
---|
8 | import { Compiler } from '@angular/core';
|
---|
9 | import { CompilerOptions } from '@angular/core';
|
---|
10 | import { Component } from '@angular/core';
|
---|
11 | import { ComponentFactory } from '@angular/core';
|
---|
12 | import { ComponentRef } from '@angular/core';
|
---|
13 | import { DebugElement } from '@angular/core';
|
---|
14 | import { Directive } from '@angular/core';
|
---|
15 | import { ElementRef } from '@angular/core';
|
---|
16 | import { InjectFlags } from '@angular/core';
|
---|
17 | import { InjectionToken } from '@angular/core';
|
---|
18 | import { Injector } from '@angular/core';
|
---|
19 | import { NgModule } from '@angular/core';
|
---|
20 | import { NgZone } from '@angular/core';
|
---|
21 | import { Pipe } from '@angular/core';
|
---|
22 | import { PlatformRef } from '@angular/core';
|
---|
23 | import { ProviderToken } from '@angular/core';
|
---|
24 | import { SchemaMetadata } from '@angular/core';
|
---|
25 | import { Type } from '@angular/core';
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * This API should be removed. But doing so seems to break `google3` and so it requires a bit of
|
---|
29 | * investigation.
|
---|
30 | *
|
---|
31 | * A work around is to mark it as `@codeGenApi` for now and investigate later.
|
---|
32 | *
|
---|
33 | * @codeGenApi
|
---|
34 | */
|
---|
35 | export declare const __core_private_testing_placeholder__ = "";
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * @deprecated use `waitForAsync()`, (expected removal in v12)
|
---|
39 | * @see {@link waitForAsync}
|
---|
40 | * @publicApi
|
---|
41 | * */
|
---|
42 | export declare function async(fn: Function): (done: any) => any;
|
---|
43 |
|
---|
44 | /**
|
---|
45 | * Fixture for debugging and testing a component.
|
---|
46 | *
|
---|
47 | * @publicApi
|
---|
48 | */
|
---|
49 | export declare class ComponentFixture<T> {
|
---|
50 | componentRef: ComponentRef<T>;
|
---|
51 | ngZone: NgZone | null;
|
---|
52 | private _autoDetect;
|
---|
53 | /**
|
---|
54 | * The DebugElement associated with the root element of this component.
|
---|
55 | */
|
---|
56 | debugElement: DebugElement;
|
---|
57 | /**
|
---|
58 | * The instance of the root component class.
|
---|
59 | */
|
---|
60 | componentInstance: T;
|
---|
61 | /**
|
---|
62 | * The native element at the root of the component.
|
---|
63 | */
|
---|
64 | nativeElement: any;
|
---|
65 | /**
|
---|
66 | * The ElementRef for the element at the root of the component.
|
---|
67 | */
|
---|
68 | elementRef: ElementRef;
|
---|
69 | /**
|
---|
70 | * The ChangeDetectorRef for the component
|
---|
71 | */
|
---|
72 | changeDetectorRef: ChangeDetectorRef;
|
---|
73 | private _renderer;
|
---|
74 | private _isStable;
|
---|
75 | private _isDestroyed;
|
---|
76 | private _resolve;
|
---|
77 | private _promise;
|
---|
78 | private _onUnstableSubscription;
|
---|
79 | private _onStableSubscription;
|
---|
80 | private _onMicrotaskEmptySubscription;
|
---|
81 | private _onErrorSubscription;
|
---|
82 | constructor(componentRef: ComponentRef<T>, ngZone: NgZone | null, _autoDetect: boolean);
|
---|
83 | private _tick;
|
---|
84 | /**
|
---|
85 | * Trigger a change detection cycle for the component.
|
---|
86 | */
|
---|
87 | detectChanges(checkNoChanges?: boolean): void;
|
---|
88 | /**
|
---|
89 | * Do a change detection run to make sure there were no changes.
|
---|
90 | */
|
---|
91 | checkNoChanges(): void;
|
---|
92 | /**
|
---|
93 | * Set whether the fixture should autodetect changes.
|
---|
94 | *
|
---|
95 | * Also runs detectChanges once so that any existing change is detected.
|
---|
96 | */
|
---|
97 | autoDetectChanges(autoDetect?: boolean): void;
|
---|
98 | /**
|
---|
99 | * Return whether the fixture is currently stable or has async tasks that have not been completed
|
---|
100 | * yet.
|
---|
101 | */
|
---|
102 | isStable(): boolean;
|
---|
103 | /**
|
---|
104 | * Get a promise that resolves when the fixture is stable.
|
---|
105 | *
|
---|
106 | * This can be used to resume testing after events have triggered asynchronous activity or
|
---|
107 | * asynchronous change detection.
|
---|
108 | */
|
---|
109 | whenStable(): Promise<any>;
|
---|
110 | private _getRenderer;
|
---|
111 | /**
|
---|
112 | * Get a promise that resolves when the ui state is stable following animations.
|
---|
113 | */
|
---|
114 | whenRenderingDone(): Promise<any>;
|
---|
115 | /**
|
---|
116 | * Trigger component destruction.
|
---|
117 | */
|
---|
118 | destroy(): void;
|
---|
119 | }
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * @publicApi
|
---|
123 | */
|
---|
124 | export declare const ComponentFixtureAutoDetect: InjectionToken<boolean[]>;
|
---|
125 |
|
---|
126 | /**
|
---|
127 | * @publicApi
|
---|
128 | */
|
---|
129 | export declare const ComponentFixtureNoNgZone: InjectionToken<boolean[]>;
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Discard all remaining periodic tasks.
|
---|
133 | *
|
---|
134 | * @publicApi
|
---|
135 | */
|
---|
136 | export declare function discardPeriodicTasks(): void;
|
---|
137 |
|
---|
138 | /**
|
---|
139 | * Wraps a function to be executed in the `fakeAsync` zone:
|
---|
140 | * - Microtasks are manually executed by calling `flushMicrotasks()`.
|
---|
141 | * - Timers are synchronous; `tick()` simulates the asynchronous passage of time.
|
---|
142 | *
|
---|
143 | * If there are any pending timers at the end of the function, an exception is thrown.
|
---|
144 | *
|
---|
145 | * Can be used to wrap `inject()` calls.
|
---|
146 | *
|
---|
147 | * @param fn The function that you want to wrap in the `fakeAysnc` zone.
|
---|
148 | *
|
---|
149 | * @usageNotes
|
---|
150 | * ### Example
|
---|
151 | *
|
---|
152 | * {@example core/testing/ts/fake_async.ts region='basic'}
|
---|
153 | *
|
---|
154 | *
|
---|
155 | * @returns The function wrapped to be executed in the `fakeAsync` zone.
|
---|
156 | * Any arguments passed when calling this returned function will be passed through to the `fn`
|
---|
157 | * function in the parameters when it is called.
|
---|
158 | *
|
---|
159 | * @publicApi
|
---|
160 | */
|
---|
161 | export declare function fakeAsync(fn: Function): (...args: any[]) => any;
|
---|
162 |
|
---|
163 | /**
|
---|
164 | * Simulates the asynchronous passage of time for the timers in the `fakeAsync` zone by
|
---|
165 | * draining the macrotask queue until it is empty.
|
---|
166 | *
|
---|
167 | * @param maxTurns The maximum number of times the scheduler attempts to clear its queue before
|
---|
168 | * throwing an error.
|
---|
169 | * @returns The simulated time elapsed, in milliseconds.
|
---|
170 | *
|
---|
171 | * @publicApi
|
---|
172 | */
|
---|
173 | export declare function flush(maxTurns?: number): number;
|
---|
174 |
|
---|
175 | /**
|
---|
176 | * Flush any pending microtasks.
|
---|
177 | *
|
---|
178 | * @publicApi
|
---|
179 | */
|
---|
180 | export declare function flushMicrotasks(): void;
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Returns a singleton of the applicable `TestBed`.
|
---|
184 | *
|
---|
185 | * It will be either an instance of `TestBedViewEngine` or `TestBedRender3`.
|
---|
186 | *
|
---|
187 | * @publicApi
|
---|
188 | */
|
---|
189 | export declare const getTestBed: () => TestBed;
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * Allows injecting dependencies in `beforeEach()` and `it()`.
|
---|
193 | *
|
---|
194 | * Example:
|
---|
195 | *
|
---|
196 | * ```
|
---|
197 | * beforeEach(inject([Dependency, AClass], (dep, object) => {
|
---|
198 | * // some code that uses `dep` and `object`
|
---|
199 | * // ...
|
---|
200 | * }));
|
---|
201 | *
|
---|
202 | * it('...', inject([AClass], (object) => {
|
---|
203 | * object.doSomething();
|
---|
204 | * expect(...);
|
---|
205 | * })
|
---|
206 | * ```
|
---|
207 | *
|
---|
208 | * @publicApi
|
---|
209 | */
|
---|
210 | export declare function inject(tokens: any[], fn: Function): () => any;
|
---|
211 |
|
---|
212 | /**
|
---|
213 | * @publicApi
|
---|
214 | */
|
---|
215 | export declare class InjectSetupWrapper {
|
---|
216 | private _moduleDef;
|
---|
217 | constructor(_moduleDef: () => TestModuleMetadata);
|
---|
218 | private _addModule;
|
---|
219 | inject(tokens: any[], fn: Function): () => any;
|
---|
220 | }
|
---|
221 |
|
---|
222 |
|
---|
223 | /**
|
---|
224 | * Type used for modifications to metadata
|
---|
225 | *
|
---|
226 | * @publicApi
|
---|
227 | */
|
---|
228 | export declare type MetadataOverride<T> = {
|
---|
229 | add?: Partial<T>;
|
---|
230 | remove?: Partial<T>;
|
---|
231 | set?: Partial<T>;
|
---|
232 | };
|
---|
233 |
|
---|
234 | /**
|
---|
235 | * Object used to configure the test module teardown behavior in `TestBed`.
|
---|
236 | * @publicApi
|
---|
237 | */
|
---|
238 | export declare interface ModuleTeardownOptions {
|
---|
239 | /** Whether the test module should be destroyed after every test. */
|
---|
240 | destroyAfterEach: boolean;
|
---|
241 | /** Whether errors during test module destruction should be re-thrown. Defaults to `true`. */
|
---|
242 | rethrowErrors?: boolean;
|
---|
243 | }
|
---|
244 |
|
---|
245 | /**
|
---|
246 | * Clears out the shared fake async zone for a test.
|
---|
247 | * To be called in a global `beforeEach`.
|
---|
248 | *
|
---|
249 | * @publicApi
|
---|
250 | */
|
---|
251 | export declare function resetFakeAsyncZone(): void;
|
---|
252 |
|
---|
253 | /**
|
---|
254 | * @publicApi
|
---|
255 | */
|
---|
256 | export declare interface TestBed {
|
---|
257 | platform: PlatformRef;
|
---|
258 | ngModule: Type<any> | Type<any>[];
|
---|
259 | /**
|
---|
260 | * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
---|
261 | * angular module. These are common to every test in the suite.
|
---|
262 | *
|
---|
263 | * This may only be called once, to set up the common providers for the current test
|
---|
264 | * suite on the current platform. If you absolutely need to change the providers,
|
---|
265 | * first use `resetTestEnvironment`.
|
---|
266 | *
|
---|
267 | * Test modules and platforms for individual platforms are available from
|
---|
268 | * '@angular/<platform_name>/testing'.
|
---|
269 | */
|
---|
270 | initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, options?: TestEnvironmentOptions): void;
|
---|
271 | initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): void;
|
---|
272 | /**
|
---|
273 | * Reset the providers for the test injector.
|
---|
274 | */
|
---|
275 | resetTestEnvironment(): void;
|
---|
276 | resetTestingModule(): void;
|
---|
277 | configureCompiler(config: {
|
---|
278 | providers?: any[];
|
---|
279 | useJit?: boolean;
|
---|
280 | }): void;
|
---|
281 | configureTestingModule(moduleDef: TestModuleMetadata): void;
|
---|
282 | compileComponents(): Promise<any>;
|
---|
283 | inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
---|
284 | inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T | null;
|
---|
285 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
286 | get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
---|
287 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
288 | get(token: any, notFoundValue?: any): any;
|
---|
289 | execute(tokens: any[], fn: Function, context?: any): any;
|
---|
290 | overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void;
|
---|
291 | overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void;
|
---|
292 | overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void;
|
---|
293 | overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): void;
|
---|
294 | /**
|
---|
295 | * Overwrites all providers for the given token with the given provider definition.
|
---|
296 | */
|
---|
297 | overrideProvider(token: any, provider: {
|
---|
298 | useFactory: Function;
|
---|
299 | deps: any[];
|
---|
300 | }): void;
|
---|
301 | overrideProvider(token: any, provider: {
|
---|
302 | useValue: any;
|
---|
303 | }): void;
|
---|
304 | overrideProvider(token: any, provider: {
|
---|
305 | useFactory?: Function;
|
---|
306 | useValue?: any;
|
---|
307 | deps?: any[];
|
---|
308 | }): void;
|
---|
309 | overrideTemplateUsingTestingModule(component: Type<any>, template: string): void;
|
---|
310 | createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
---|
311 | }
|
---|
312 |
|
---|
313 | /**
|
---|
314 | * @description
|
---|
315 | * Configures and initializes environment for unit testing and provides methods for
|
---|
316 | * creating components and services in unit tests.
|
---|
317 | *
|
---|
318 | * `TestBed` is the primary api for writing unit tests for Angular applications and libraries.
|
---|
319 | *
|
---|
320 | * Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
|
---|
321 | * according to the compiler used.
|
---|
322 | *
|
---|
323 | * @publicApi
|
---|
324 | */
|
---|
325 | export declare const TestBed: TestBedStatic;
|
---|
326 |
|
---|
327 | /**
|
---|
328 | * Static methods implemented by the `TestBedViewEngine` and `TestBedRender3`
|
---|
329 | *
|
---|
330 | * @publicApi
|
---|
331 | */
|
---|
332 | export declare interface TestBedStatic {
|
---|
333 | new (...args: any[]): TestBed;
|
---|
334 | initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, options?: {
|
---|
335 | teardown?: ModuleTeardownOptions;
|
---|
336 | }): TestBed;
|
---|
337 | initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed;
|
---|
338 | /**
|
---|
339 | * Reset the providers for the test injector.
|
---|
340 | */
|
---|
341 | resetTestEnvironment(): void;
|
---|
342 | resetTestingModule(): TestBedStatic;
|
---|
343 | /**
|
---|
344 | * Allows overriding default compiler providers and settings
|
---|
345 | * which are defined in test_injector.js
|
---|
346 | */
|
---|
347 | configureCompiler(config: {
|
---|
348 | providers?: any[];
|
---|
349 | useJit?: boolean;
|
---|
350 | }): TestBedStatic;
|
---|
351 | /**
|
---|
352 | * Allows overriding default providers, directives, pipes, modules of the test injector,
|
---|
353 | * which are defined in test_injector.js
|
---|
354 | */
|
---|
355 | configureTestingModule(moduleDef: TestModuleMetadata): TestBedStatic;
|
---|
356 | /**
|
---|
357 | * Compile components with a `templateUrl` for the test's NgModule.
|
---|
358 | * It is necessary to call this function
|
---|
359 | * as fetching urls is asynchronous.
|
---|
360 | */
|
---|
361 | compileComponents(): Promise<any>;
|
---|
362 | overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic;
|
---|
363 | overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBedStatic;
|
---|
364 | overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBedStatic;
|
---|
365 | overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBedStatic;
|
---|
366 | overrideTemplate(component: Type<any>, template: string): TestBedStatic;
|
---|
367 | /**
|
---|
368 | * Overrides the template of the given component, compiling the template
|
---|
369 | * in the context of the TestingModule.
|
---|
370 | *
|
---|
371 | * Note: This works for JIT and AOTed components as well.
|
---|
372 | */
|
---|
373 | overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBedStatic;
|
---|
374 | /**
|
---|
375 | * Overwrites all providers for the given token with the given provider definition.
|
---|
376 | *
|
---|
377 | * Note: This works for JIT and AOTed components as well.
|
---|
378 | */
|
---|
379 | overrideProvider(token: any, provider: {
|
---|
380 | useFactory: Function;
|
---|
381 | deps: any[];
|
---|
382 | }): TestBedStatic;
|
---|
383 | overrideProvider(token: any, provider: {
|
---|
384 | useValue: any;
|
---|
385 | }): TestBedStatic;
|
---|
386 | overrideProvider(token: any, provider: {
|
---|
387 | useFactory?: Function;
|
---|
388 | useValue?: any;
|
---|
389 | deps?: any[];
|
---|
390 | }): TestBedStatic;
|
---|
391 | inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
---|
392 | inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T | null;
|
---|
393 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
394 | get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
---|
395 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
396 | get(token: any, notFoundValue?: any): any;
|
---|
397 | createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
---|
398 | }
|
---|
399 |
|
---|
400 | /**
|
---|
401 | * An abstract class for inserting the root test component element in a platform independent way.
|
---|
402 | *
|
---|
403 | * @publicApi
|
---|
404 | */
|
---|
405 | export declare class TestComponentRenderer {
|
---|
406 | insertRootElement(rootElementId: string): void;
|
---|
407 | removeAllRootElements?(): void;
|
---|
408 | }
|
---|
409 |
|
---|
410 | /**
|
---|
411 | * @publicApi
|
---|
412 | */
|
---|
413 | export declare interface TestEnvironmentOptions {
|
---|
414 | aotSummaries?: () => any[];
|
---|
415 | teardown?: ModuleTeardownOptions;
|
---|
416 | }
|
---|
417 |
|
---|
418 | /**
|
---|
419 | * @publicApi
|
---|
420 | */
|
---|
421 | export declare type TestModuleMetadata = {
|
---|
422 | providers?: any[];
|
---|
423 | declarations?: any[];
|
---|
424 | imports?: any[];
|
---|
425 | schemas?: Array<SchemaMetadata | any[]>;
|
---|
426 | aotSummaries?: () => any[];
|
---|
427 | teardown?: ModuleTeardownOptions;
|
---|
428 | };
|
---|
429 |
|
---|
430 | /**
|
---|
431 | * Simulates the asynchronous passage of time for the timers in the `fakeAsync` zone.
|
---|
432 | *
|
---|
433 | * The microtasks queue is drained at the very start of this function and after any timer callback
|
---|
434 | * has been executed.
|
---|
435 | *
|
---|
436 | * @param millis The number of milliseconds to advance the virtual timer.
|
---|
437 | * @param tickOptions The options to pass to the `tick()` function.
|
---|
438 | *
|
---|
439 | * @usageNotes
|
---|
440 | *
|
---|
441 | * The `tick()` option is a flag called `processNewMacroTasksSynchronously`,
|
---|
442 | * which determines whether or not to invoke new macroTasks.
|
---|
443 | *
|
---|
444 | * If you provide a `tickOptions` object, but do not specify a
|
---|
445 | * `processNewMacroTasksSynchronously` property (`tick(100, {})`),
|
---|
446 | * then `processNewMacroTasksSynchronously` defaults to true.
|
---|
447 | *
|
---|
448 | * If you omit the `tickOptions` parameter (`tick(100))`), then
|
---|
449 | * `tickOptions` defaults to `{processNewMacroTasksSynchronously: true}`.
|
---|
450 | *
|
---|
451 | * ### Example
|
---|
452 | *
|
---|
453 | * {@example core/testing/ts/fake_async.ts region='basic'}
|
---|
454 | *
|
---|
455 | * The following example includes a nested timeout (new macroTask), and
|
---|
456 | * the `tickOptions` parameter is allowed to default. In this case,
|
---|
457 | * `processNewMacroTasksSynchronously` defaults to true, and the nested
|
---|
458 | * function is executed on each tick.
|
---|
459 | *
|
---|
460 | * ```
|
---|
461 | * it ('test with nested setTimeout', fakeAsync(() => {
|
---|
462 | * let nestedTimeoutInvoked = false;
|
---|
463 | * function funcWithNestedTimeout() {
|
---|
464 | * setTimeout(() => {
|
---|
465 | * nestedTimeoutInvoked = true;
|
---|
466 | * });
|
---|
467 | * };
|
---|
468 | * setTimeout(funcWithNestedTimeout);
|
---|
469 | * tick();
|
---|
470 | * expect(nestedTimeoutInvoked).toBe(true);
|
---|
471 | * }));
|
---|
472 | * ```
|
---|
473 | *
|
---|
474 | * In the following case, `processNewMacroTasksSynchronously` is explicitly
|
---|
475 | * set to false, so the nested timeout function is not invoked.
|
---|
476 | *
|
---|
477 | * ```
|
---|
478 | * it ('test with nested setTimeout', fakeAsync(() => {
|
---|
479 | * let nestedTimeoutInvoked = false;
|
---|
480 | * function funcWithNestedTimeout() {
|
---|
481 | * setTimeout(() => {
|
---|
482 | * nestedTimeoutInvoked = true;
|
---|
483 | * });
|
---|
484 | * };
|
---|
485 | * setTimeout(funcWithNestedTimeout);
|
---|
486 | * tick(0, {processNewMacroTasksSynchronously: false});
|
---|
487 | * expect(nestedTimeoutInvoked).toBe(false);
|
---|
488 | * }));
|
---|
489 | * ```
|
---|
490 | *
|
---|
491 | *
|
---|
492 | * @publicApi
|
---|
493 | */
|
---|
494 | export declare function tick(millis?: number, tickOptions?: {
|
---|
495 | processNewMacroTasksSynchronously: boolean;
|
---|
496 | }): void;
|
---|
497 |
|
---|
498 |
|
---|
499 | /**
|
---|
500 | * Wraps a test function in an asynchronous test zone. The test will automatically
|
---|
501 | * complete when all asynchronous calls within this zone are done. Can be used
|
---|
502 | * to wrap an {@link inject} call.
|
---|
503 | *
|
---|
504 | * Example:
|
---|
505 | *
|
---|
506 | * ```
|
---|
507 | * it('...', waitForAsync(inject([AClass], (object) => {
|
---|
508 | * object.doSomething.then(() => {
|
---|
509 | * expect(...);
|
---|
510 | * })
|
---|
511 | * });
|
---|
512 | * ```
|
---|
513 | *
|
---|
514 | * @publicApi
|
---|
515 | */
|
---|
516 | export declare function waitForAsync(fn: Function): (done: any) => any;
|
---|
517 |
|
---|
518 | /**
|
---|
519 | * @publicApi
|
---|
520 | */
|
---|
521 | export declare function withModule(moduleDef: TestModuleMetadata): InjectSetupWrapper;
|
---|
522 |
|
---|
523 | export declare function withModule(moduleDef: TestModuleMetadata, fn: Function): () => any;
|
---|
524 |
|
---|
525 | /**
|
---|
526 | * @description
|
---|
527 | * Configures and initializes environment for unit testing and provides methods for
|
---|
528 | * creating components and services in unit tests.
|
---|
529 | *
|
---|
530 | * `TestBed` is the primary api for writing unit tests for Angular applications and libraries.
|
---|
531 | *
|
---|
532 | * Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
|
---|
533 | * according to the compiler used.
|
---|
534 | */
|
---|
535 | export declare class ɵangular_packages_core_testing_testing_a implements TestBed {
|
---|
536 | /**
|
---|
537 | * Teardown options that have been configured at the environment level.
|
---|
538 | * Used as a fallback if no instance-level options have been provided.
|
---|
539 | */
|
---|
540 | private static _environmentTeardownOptions;
|
---|
541 | /**
|
---|
542 | * Teardown options that have been configured at the `TestBed` instance level.
|
---|
543 | * These options take precedence over the environemnt-level ones.
|
---|
544 | */
|
---|
545 | private _instanceTeardownOptions;
|
---|
546 | /**
|
---|
547 | * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
---|
548 | * angular module. These are common to every test in the suite.
|
---|
549 | *
|
---|
550 | * This may only be called once, to set up the common providers for the current test
|
---|
551 | * suite on the current platform. If you absolutely need to change the providers,
|
---|
552 | * first use `resetTestEnvironment`.
|
---|
553 | *
|
---|
554 | * Test modules and platforms for individual platforms are available from
|
---|
555 | * '@angular/<platform_name>/testing'.
|
---|
556 | */
|
---|
557 | static initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, summariesOrOptions?: TestEnvironmentOptions | (() => any[])): ɵangular_packages_core_testing_testing_a;
|
---|
558 | /**
|
---|
559 | * Reset the providers for the test injector.
|
---|
560 | */
|
---|
561 | static resetTestEnvironment(): void;
|
---|
562 | static resetTestingModule(): TestBedStatic;
|
---|
563 | /**
|
---|
564 | * Allows overriding default compiler providers and settings
|
---|
565 | * which are defined in test_injector.js
|
---|
566 | */
|
---|
567 | static configureCompiler(config: {
|
---|
568 | providers?: any[];
|
---|
569 | useJit?: boolean;
|
---|
570 | }): TestBedStatic;
|
---|
571 | /**
|
---|
572 | * Allows overriding default providers, directives, pipes, modules of the test injector,
|
---|
573 | * which are defined in test_injector.js
|
---|
574 | */
|
---|
575 | static configureTestingModule(moduleDef: TestModuleMetadata): TestBedStatic;
|
---|
576 | /**
|
---|
577 | * Compile components with a `templateUrl` for the test's NgModule.
|
---|
578 | * It is necessary to call this function
|
---|
579 | * as fetching urls is asynchronous.
|
---|
580 | */
|
---|
581 | static compileComponents(): Promise<any>;
|
---|
582 | static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic;
|
---|
583 | static overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBedStatic;
|
---|
584 | static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBedStatic;
|
---|
585 | static overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBedStatic;
|
---|
586 | static overrideTemplate(component: Type<any>, template: string): TestBedStatic;
|
---|
587 | /**
|
---|
588 | * Overrides the template of the given component, compiling the template
|
---|
589 | * in the context of the TestingModule.
|
---|
590 | *
|
---|
591 | * Note: This works for JIT and AOTed components as well.
|
---|
592 | */
|
---|
593 | static overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBedStatic;
|
---|
594 | /**
|
---|
595 | * Overwrites all providers for the given token with the given provider definition.
|
---|
596 | *
|
---|
597 | * Note: This works for JIT and AOTed components as well.
|
---|
598 | */
|
---|
599 | static overrideProvider(token: any, provider: {
|
---|
600 | useFactory: Function;
|
---|
601 | deps: any[];
|
---|
602 | }): TestBedStatic;
|
---|
603 | static overrideProvider(token: any, provider: {
|
---|
604 | useValue: any;
|
---|
605 | }): TestBedStatic;
|
---|
606 | static inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
---|
607 | static inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T | null;
|
---|
608 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
609 | static get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
---|
610 | /**
|
---|
611 | * @deprecated from v9.0.0 use TestBed.inject
|
---|
612 | * @suppress {duplicate}
|
---|
613 | */
|
---|
614 | static get(token: any, notFoundValue?: any): any;
|
---|
615 | static createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
---|
616 | static shouldTearDownTestingModule(): boolean;
|
---|
617 | static tearDownTestingModule(): void;
|
---|
618 | private _instantiated;
|
---|
619 | private _compiler;
|
---|
620 | private _moduleRef;
|
---|
621 | private _moduleFactory;
|
---|
622 | private _pendingModuleFactory;
|
---|
623 | private _compilerOptions;
|
---|
624 | private _moduleOverrides;
|
---|
625 | private _componentOverrides;
|
---|
626 | private _directiveOverrides;
|
---|
627 | private _pipeOverrides;
|
---|
628 | private _providers;
|
---|
629 | private _declarations;
|
---|
630 | private _imports;
|
---|
631 | private _schemas;
|
---|
632 | private _activeFixtures;
|
---|
633 | private _testEnvAotSummaries;
|
---|
634 | private _aotSummaries;
|
---|
635 | private _templateOverrides;
|
---|
636 | private _isRoot;
|
---|
637 | private _rootProviderOverrides;
|
---|
638 | platform: PlatformRef;
|
---|
639 | ngModule: Type<any> | Type<any>[];
|
---|
640 | /**
|
---|
641 | * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
---|
642 | * angular module. These are common to every test in the suite.
|
---|
643 | *
|
---|
644 | * This may only be called once, to set up the common providers for the current test
|
---|
645 | * suite on the current platform. If you absolutely need to change the providers,
|
---|
646 | * first use `resetTestEnvironment`.
|
---|
647 | *
|
---|
648 | * Test modules and platforms for individual platforms are available from
|
---|
649 | * '@angular/<platform_name>/testing'.
|
---|
650 | */
|
---|
651 | initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, summariesOrOptions?: TestEnvironmentOptions | (() => any[])): void;
|
---|
652 | /**
|
---|
653 | * Reset the providers for the test injector.
|
---|
654 | */
|
---|
655 | resetTestEnvironment(): void;
|
---|
656 | resetTestingModule(): void;
|
---|
657 | configureCompiler(config: {
|
---|
658 | providers?: any[];
|
---|
659 | useJit?: boolean;
|
---|
660 | }): void;
|
---|
661 | configureTestingModule(moduleDef: TestModuleMetadata): void;
|
---|
662 | compileComponents(): Promise<any>;
|
---|
663 | private _initIfNeeded;
|
---|
664 | private _createCompilerAndModule;
|
---|
665 | private _assertNotInstantiated;
|
---|
666 | inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
---|
667 | inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T | null;
|
---|
668 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
669 | get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
---|
670 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
671 | get(token: any, notFoundValue?: any): any;
|
---|
672 | execute(tokens: any[], fn: Function, context?: any): any;
|
---|
673 | overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void;
|
---|
674 | overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void;
|
---|
675 | overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void;
|
---|
676 | overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): void;
|
---|
677 | /**
|
---|
678 | * Overwrites all providers for the given token with the given provider definition.
|
---|
679 | */
|
---|
680 | overrideProvider(token: any, provider: {
|
---|
681 | useFactory: Function;
|
---|
682 | deps: any[];
|
---|
683 | }): void;
|
---|
684 | overrideProvider(token: any, provider: {
|
---|
685 | useValue: any;
|
---|
686 | }): void;
|
---|
687 | private overrideProviderImpl;
|
---|
688 | overrideTemplateUsingTestingModule(component: Type<any>, template: string): void;
|
---|
689 | createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
---|
690 | private destroyActiveFixtures;
|
---|
691 | private shouldRethrowTeardownErrors;
|
---|
692 | shouldTearDownTestingModule(): boolean;
|
---|
693 | tearDownTestingModule(): void;
|
---|
694 | }
|
---|
695 |
|
---|
696 | /**
|
---|
697 | * @description
|
---|
698 | * Configures and initializes environment for unit testing and provides methods for
|
---|
699 | * creating components and services in unit tests.
|
---|
700 | *
|
---|
701 | * TestBed is the primary api for writing unit tests for Angular applications and libraries.
|
---|
702 | *
|
---|
703 | * Note: Use `TestBed` in tests. It will be set to either `TestBedViewEngine` or `TestBedRender3`
|
---|
704 | * according to the compiler used.
|
---|
705 | */
|
---|
706 | export declare class ɵangular_packages_core_testing_testing_b implements TestBed {
|
---|
707 | /**
|
---|
708 | * Teardown options that have been configured at the environment level.
|
---|
709 | * Used as a fallback if no instance-level options have been provided.
|
---|
710 | */
|
---|
711 | private static _environmentTeardownOptions;
|
---|
712 | /**
|
---|
713 | * Teardown options that have been configured at the `TestBed` instance level.
|
---|
714 | * These options take precedence over the environemnt-level ones.
|
---|
715 | */
|
---|
716 | private _instanceTeardownOptions;
|
---|
717 | /**
|
---|
718 | * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
---|
719 | * angular module. These are common to every test in the suite.
|
---|
720 | *
|
---|
721 | * This may only be called once, to set up the common providers for the current test
|
---|
722 | * suite on the current platform. If you absolutely need to change the providers,
|
---|
723 | * first use `resetTestEnvironment`.
|
---|
724 | *
|
---|
725 | * Test modules and platforms for individual platforms are available from
|
---|
726 | * '@angular/<platform_name>/testing'.
|
---|
727 | *
|
---|
728 | * @publicApi
|
---|
729 | */
|
---|
730 | static initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, summariesOrOptions?: TestEnvironmentOptions | (() => any[])): TestBed;
|
---|
731 | /**
|
---|
732 | * Reset the providers for the test injector.
|
---|
733 | *
|
---|
734 | * @publicApi
|
---|
735 | */
|
---|
736 | static resetTestEnvironment(): void;
|
---|
737 | static configureCompiler(config: {
|
---|
738 | providers?: any[];
|
---|
739 | useJit?: boolean;
|
---|
740 | }): TestBedStatic;
|
---|
741 | /**
|
---|
742 | * Allows overriding default providers, directives, pipes, modules of the test injector,
|
---|
743 | * which are defined in test_injector.js
|
---|
744 | */
|
---|
745 | static configureTestingModule(moduleDef: TestModuleMetadata): TestBedStatic;
|
---|
746 | /**
|
---|
747 | * Compile components with a `templateUrl` for the test's NgModule.
|
---|
748 | * It is necessary to call this function
|
---|
749 | * as fetching urls is asynchronous.
|
---|
750 | */
|
---|
751 | static compileComponents(): Promise<any>;
|
---|
752 | static overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic;
|
---|
753 | static overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBedStatic;
|
---|
754 | static overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBedStatic;
|
---|
755 | static overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBedStatic;
|
---|
756 | static overrideTemplate(component: Type<any>, template: string): TestBedStatic;
|
---|
757 | /**
|
---|
758 | * Overrides the template of the given component, compiling the template
|
---|
759 | * in the context of the TestingModule.
|
---|
760 | *
|
---|
761 | * Note: This works for JIT and AOTed components as well.
|
---|
762 | */
|
---|
763 | static overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBedStatic;
|
---|
764 | static overrideProvider(token: any, provider: {
|
---|
765 | useFactory: Function;
|
---|
766 | deps: any[];
|
---|
767 | }): TestBedStatic;
|
---|
768 | static overrideProvider(token: any, provider: {
|
---|
769 | useValue: any;
|
---|
770 | }): TestBedStatic;
|
---|
771 | static inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
---|
772 | static inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T | null;
|
---|
773 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
774 | static get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
---|
775 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
776 | static get(token: any, notFoundValue?: any): any;
|
---|
777 | static createComponent<T>(component: Type<T>): ComponentFixture<T>;
|
---|
778 | static resetTestingModule(): TestBedStatic;
|
---|
779 | static shouldTearDownTestingModule(): boolean;
|
---|
780 | static tearDownTestingModule(): void;
|
---|
781 | platform: PlatformRef;
|
---|
782 | ngModule: Type<any> | Type<any>[];
|
---|
783 | private _compiler;
|
---|
784 | private _testModuleRef;
|
---|
785 | private _activeFixtures;
|
---|
786 | private _globalCompilationChecked;
|
---|
787 | /**
|
---|
788 | * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
|
---|
789 | * angular module. These are common to every test in the suite.
|
---|
790 | *
|
---|
791 | * This may only be called once, to set up the common providers for the current test
|
---|
792 | * suite on the current platform. If you absolutely need to change the providers,
|
---|
793 | * first use `resetTestEnvironment`.
|
---|
794 | *
|
---|
795 | * Test modules and platforms for individual platforms are available from
|
---|
796 | * '@angular/<platform_name>/testing'.
|
---|
797 | *
|
---|
798 | * @publicApi
|
---|
799 | */
|
---|
800 | initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, summariesOrOptions?: {
|
---|
801 | teardown?: ModuleTeardownOptions;
|
---|
802 | } | (() => any[])): void;
|
---|
803 | /**
|
---|
804 | * Reset the providers for the test injector.
|
---|
805 | *
|
---|
806 | * @publicApi
|
---|
807 | */
|
---|
808 | resetTestEnvironment(): void;
|
---|
809 | resetTestingModule(): void;
|
---|
810 | configureCompiler(config: {
|
---|
811 | providers?: any[];
|
---|
812 | useJit?: boolean;
|
---|
813 | }): void;
|
---|
814 | configureTestingModule(moduleDef: TestModuleMetadata): void;
|
---|
815 | compileComponents(): Promise<any>;
|
---|
816 | inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
---|
817 | inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T | null;
|
---|
818 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
819 | get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
|
---|
820 | /** @deprecated from v9.0.0 use TestBed.inject */
|
---|
821 | get(token: any, notFoundValue?: any): any;
|
---|
822 | execute(tokens: any[], fn: Function, context?: any): any;
|
---|
823 | overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void;
|
---|
824 | overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void;
|
---|
825 | overrideTemplateUsingTestingModule(component: Type<any>, template: string): void;
|
---|
826 | overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void;
|
---|
827 | overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): void;
|
---|
828 | /**
|
---|
829 | * Overwrites all providers for the given token with the given provider definition.
|
---|
830 | */
|
---|
831 | overrideProvider(token: any, provider: {
|
---|
832 | useFactory?: Function;
|
---|
833 | useValue?: any;
|
---|
834 | deps?: any[];
|
---|
835 | }): void;
|
---|
836 | createComponent<T>(type: Type<T>): ComponentFixture<T>;
|
---|
837 | private assertNotInstantiated;
|
---|
838 | /**
|
---|
839 | * Check whether the module scoping queue should be flushed, and flush it if needed.
|
---|
840 | *
|
---|
841 | * When the TestBed is reset, it clears the JIT module compilation queue, cancelling any
|
---|
842 | * in-progress module compilation. This creates a potential hazard - the very first time the
|
---|
843 | * TestBed is initialized (or if it's reset without being initialized), there may be pending
|
---|
844 | * compilations of modules declared in global scope. These compilations should be finished.
|
---|
845 | *
|
---|
846 | * To ensure that globally declared modules have their components scoped properly, this function
|
---|
847 | * is called whenever TestBed is initialized or reset. The _first_ time that this happens, prior
|
---|
848 | * to any other operations, the scoping queue is flushed.
|
---|
849 | */
|
---|
850 | private checkGlobalCompilationFinished;
|
---|
851 | private destroyActiveFixtures;
|
---|
852 | private shouldRethrowTeardownErrors;
|
---|
853 | shouldTearDownTestingModule(): boolean;
|
---|
854 | tearDownTestingModule(): void;
|
---|
855 | }
|
---|
856 |
|
---|
857 | export declare function ɵangular_packages_core_testing_testing_c(): ɵangular_packages_core_testing_testing_b;
|
---|
858 |
|
---|
859 | export declare class ɵMetadataOverrider {
|
---|
860 | private _references;
|
---|
861 | /**
|
---|
862 | * Creates a new instance for the given metadata class
|
---|
863 | * based on an old instance and overrides.
|
---|
864 | */
|
---|
865 | overrideMetadata<C extends T, T>(metadataClass: {
|
---|
866 | new (options: T): C;
|
---|
867 | }, oldMetadata: C, override: MetadataOverride<T>): C;
|
---|
868 | }
|
---|
869 |
|
---|
870 | /**
|
---|
871 | * Special interface to the compiler only used by testing
|
---|
872 | *
|
---|
873 | * @publicApi
|
---|
874 | */
|
---|
875 | export declare class ɵTestingCompiler extends Compiler {
|
---|
876 | get injector(): Injector;
|
---|
877 | overrideModule(module: Type<any>, overrides: MetadataOverride<NgModule>): void;
|
---|
878 | overrideDirective(directive: Type<any>, overrides: MetadataOverride<Directive>): void;
|
---|
879 | overrideComponent(component: Type<any>, overrides: MetadataOverride<Component>): void;
|
---|
880 | overridePipe(directive: Type<any>, overrides: MetadataOverride<Pipe>): void;
|
---|
881 | /**
|
---|
882 | * Allows to pass the compile summary from AOT compilation to the JIT compiler,
|
---|
883 | * so that it can use the code generated by AOT.
|
---|
884 | */
|
---|
885 | loadAotSummaries(summaries: () => any[]): void;
|
---|
886 | /**
|
---|
887 | * Gets the component factory for the given component.
|
---|
888 | * This assumes that the component has been compiled before calling this call using
|
---|
889 | * `compileModuleAndAllComponents*`.
|
---|
890 | */
|
---|
891 | getComponentFactory<T>(component: Type<T>): ComponentFactory<T>;
|
---|
892 | /**
|
---|
893 | * Returns the component type that is stored in the given error.
|
---|
894 | * This can be used for errors created by compileModule...
|
---|
895 | */
|
---|
896 | getComponentFromError(error: Error): Type<any> | null;
|
---|
897 | }
|
---|
898 |
|
---|
899 | /**
|
---|
900 | * A factory for creating a Compiler
|
---|
901 | *
|
---|
902 | * @publicApi
|
---|
903 | */
|
---|
904 | export declare abstract class ɵTestingCompilerFactory {
|
---|
905 | abstract createTestingCompiler(options?: CompilerOptions[]): ɵTestingCompiler;
|
---|
906 | }
|
---|
907 |
|
---|
908 | export { }
|
---|