testing.d.ts 27 KB

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