UNPKG

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