index.d.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. /**
  2. * @license Angular v20.1.0
  3. * (c) 2010-2025 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import '../event_dispatcher.d.js';
  7. import { InjectionToken, Type, ProviderToken, InjectOptions } from '../chrome_dev_tools_performance.d.js';
  8. import { DeferBlockDetails, DeferBlockState, ComponentRef, DebugElement, ElementRef, ChangeDetectorRef, NgZone, SchemaMetadata, DeferBlockBehavior, Binding, PlatformRef, NgModule, Component, Directive, Pipe, Navigation, NavigationNavigateOptions, NavigationOptions, NavigateEvent, NavigationCurrentEntryChangeEvent, NavigationTransition, NavigationUpdateCurrentEntryOptions, NavigationReloadOptions, NavigationResult, NavigationHistoryEntry, NavigationDestination, NavigationInterceptOptions } from '../discovery.d.js';
  9. import * as i0 from '@angular/core';
  10. import '../graph.d.js';
  11. import 'rxjs';
  12. import '../signal.d.js';
  13. import '@angular/core/primitives/di';
  14. /**
  15. * Wraps a test function in an asynchronous test zone. The test will automatically
  16. * complete when all asynchronous calls within this zone are done. Can be used
  17. * to wrap an {@link inject} call.
  18. *
  19. * Example:
  20. *
  21. * ```ts
  22. * it('...', waitForAsync(inject([AClass], (object) => {
  23. * object.doSomething.then(() => {
  24. * expect(...);
  25. * })
  26. * })));
  27. * ```
  28. *
  29. * @publicApi
  30. */
  31. declare function waitForAsync(fn: Function): (done: any) => any;
  32. /**
  33. * Represents an individual defer block for testing purposes.
  34. *
  35. * @publicApi
  36. */
  37. declare class DeferBlockFixture {
  38. private block;
  39. private componentFixture;
  40. /** @docs-private */
  41. constructor(block: DeferBlockDetails, componentFixture: ComponentFixture<unknown>);
  42. /**
  43. * Renders the specified state of the defer fixture.
  44. * @param state the defer state to render
  45. */
  46. render(state: DeferBlockState): Promise<void>;
  47. /**
  48. * Retrieves all nested child defer block fixtures
  49. * in a given defer block.
  50. */
  51. getDeferBlocks(): Promise<DeferBlockFixture[]>;
  52. }
  53. /**
  54. * Fixture for debugging and testing a component.
  55. *
  56. * @publicApi
  57. */
  58. declare class ComponentFixture<T> {
  59. componentRef: ComponentRef<T>;
  60. /**
  61. * The DebugElement associated with the root element of this component.
  62. */
  63. debugElement: DebugElement;
  64. /**
  65. * The instance of the root component class.
  66. */
  67. componentInstance: T;
  68. /**
  69. * The native element at the root of the component.
  70. */
  71. nativeElement: any;
  72. /**
  73. * The ElementRef for the element at the root of the component.
  74. */
  75. elementRef: ElementRef;
  76. /**
  77. * The ChangeDetectorRef for the component
  78. */
  79. changeDetectorRef: ChangeDetectorRef;
  80. private _renderer;
  81. private _isDestroyed;
  82. private readonly _testAppRef;
  83. private readonly pendingTasks;
  84. private readonly appErrorHandler;
  85. private readonly zonelessEnabled;
  86. private readonly scheduler;
  87. private readonly rootEffectScheduler;
  88. private readonly autoDetectDefault;
  89. private autoDetect;
  90. private subscriptions;
  91. ngZone: NgZone | null;
  92. /** @docs-private */
  93. constructor(componentRef: ComponentRef<T>);
  94. /**
  95. * Trigger a change detection cycle for the component.
  96. */
  97. detectChanges(checkNoChanges?: boolean): void;
  98. /**
  99. * Do a change detection run to make sure there were no changes.
  100. */
  101. checkNoChanges(): void;
  102. /**
  103. * Set whether the fixture should autodetect changes.
  104. *
  105. * Also runs detectChanges once so that any existing change is detected.
  106. *
  107. * @param autoDetect Whether to autodetect changes. By default, `true`.
  108. * @deprecated For `autoDetect: true`, use `autoDetectChanges()`.
  109. * We have not seen a use-case for `autoDetect: false` but `changeDetectorRef.detach()` is a close equivalent.
  110. */
  111. autoDetectChanges(autoDetect: boolean): void;
  112. /**
  113. * Enables automatically synchronizing the view, as it would in an application.
  114. *
  115. * Also runs detectChanges once so that any existing change is detected.
  116. */
  117. autoDetectChanges(): void;
  118. /**
  119. * Return whether the fixture is currently stable or has async tasks that have not been completed
  120. * yet.
  121. */
  122. isStable(): boolean;
  123. /**
  124. * Get a promise that resolves when the fixture is stable.
  125. *
  126. * This can be used to resume testing after events have triggered asynchronous activity or
  127. * asynchronous change detection.
  128. */
  129. whenStable(): Promise<any>;
  130. /**
  131. * Retrieves all defer block fixtures in the component fixture.
  132. */
  133. getDeferBlocks(): Promise<DeferBlockFixture[]>;
  134. private _getRenderer;
  135. /**
  136. * Get a promise that resolves when the ui state is stable following animations.
  137. */
  138. whenRenderingDone(): Promise<any>;
  139. /**
  140. * Trigger component destruction.
  141. */
  142. destroy(): void;
  143. }
  144. /**
  145. * Clears out the shared fake async zone for a test.
  146. * To be called in a global `beforeEach`.
  147. *
  148. * @publicApi
  149. */
  150. declare function resetFakeAsyncZone(): void;
  151. /**
  152. * Wraps a function to be executed in the `fakeAsync` zone:
  153. * - Microtasks are manually executed by calling `flushMicrotasks()`.
  154. * - Timers are synchronous; `tick()` simulates the asynchronous passage of time.
  155. *
  156. * Can be used to wrap `inject()` calls.
  157. *
  158. * @param fn The function that you want to wrap in the `fakeAsync` zone.
  159. * @param options
  160. * - flush: When true, will drain the macrotask queue after the test function completes.
  161. * When false, will throw an exception at the end of the function if there are pending timers.
  162. *
  163. * @usageNotes
  164. * ### Example
  165. *
  166. * {@example core/testing/ts/fake_async.ts region='basic'}
  167. *
  168. *
  169. * @returns The function wrapped to be executed in the `fakeAsync` zone.
  170. * Any arguments passed when calling this returned function will be passed through to the `fn`
  171. * function in the parameters when it is called.
  172. *
  173. * @publicApi
  174. */
  175. declare function fakeAsync(fn: Function, options?: {
  176. flush?: boolean;
  177. }): (...args: any[]) => any;
  178. /**
  179. * Simulates the asynchronous passage of time for the timers in the `fakeAsync` zone.
  180. *
  181. * The microtasks queue is drained at the very start of this function and after any timer callback
  182. * has been executed.
  183. *
  184. * @param millis The number of milliseconds to advance the virtual timer.
  185. * @param tickOptions The options to pass to the `tick()` function.
  186. *
  187. * @usageNotes
  188. *
  189. * The `tick()` option is a flag called `processNewMacroTasksSynchronously`,
  190. * which determines whether or not to invoke new macroTasks.
  191. *
  192. * If you provide a `tickOptions` object, but do not specify a
  193. * `processNewMacroTasksSynchronously` property (`tick(100, {})`),
  194. * then `processNewMacroTasksSynchronously` defaults to true.
  195. *
  196. * If you omit the `tickOptions` parameter (`tick(100))`), then
  197. * `tickOptions` defaults to `{processNewMacroTasksSynchronously: true}`.
  198. *
  199. * ### Example
  200. *
  201. * {@example core/testing/ts/fake_async.ts region='basic'}
  202. *
  203. * The following example includes a nested timeout (new macroTask), and
  204. * the `tickOptions` parameter is allowed to default. In this case,
  205. * `processNewMacroTasksSynchronously` defaults to true, and the nested
  206. * function is executed on each tick.
  207. *
  208. * ```ts
  209. * it ('test with nested setTimeout', fakeAsync(() => {
  210. * let nestedTimeoutInvoked = false;
  211. * function funcWithNestedTimeout() {
  212. * setTimeout(() => {
  213. * nestedTimeoutInvoked = true;
  214. * });
  215. * };
  216. * setTimeout(funcWithNestedTimeout);
  217. * tick();
  218. * expect(nestedTimeoutInvoked).toBe(true);
  219. * }));
  220. * ```
  221. *
  222. * In the following case, `processNewMacroTasksSynchronously` is explicitly
  223. * set to false, so the nested timeout function is not invoked.
  224. *
  225. * ```ts
  226. * it ('test with nested setTimeout', fakeAsync(() => {
  227. * let nestedTimeoutInvoked = false;
  228. * function funcWithNestedTimeout() {
  229. * setTimeout(() => {
  230. * nestedTimeoutInvoked = true;
  231. * });
  232. * };
  233. * setTimeout(funcWithNestedTimeout);
  234. * tick(0, {processNewMacroTasksSynchronously: false});
  235. * expect(nestedTimeoutInvoked).toBe(false);
  236. * }));
  237. * ```
  238. *
  239. *
  240. * @publicApi
  241. */
  242. declare function tick(millis?: number, tickOptions?: {
  243. processNewMacroTasksSynchronously: boolean;
  244. }): void;
  245. /**
  246. * Flushes any pending microtasks and simulates the asynchronous passage of time for the timers in
  247. * the `fakeAsync` zone by
  248. * draining the macrotask queue until it is empty.
  249. *
  250. * @param maxTurns The maximum number of times the scheduler attempts to clear its queue before
  251. * throwing an error.
  252. * @returns The simulated time elapsed, in milliseconds.
  253. *
  254. * @publicApi
  255. */
  256. declare function flush(maxTurns?: number): number;
  257. /**
  258. * Discard all remaining periodic tasks.
  259. *
  260. * @publicApi
  261. */
  262. declare function discardPeriodicTasks(): void;
  263. /**
  264. * Flush any pending microtasks.
  265. *
  266. * @publicApi
  267. */
  268. declare function flushMicrotasks(): void;
  269. /**
  270. * Type used for modifications to metadata
  271. *
  272. * @publicApi
  273. */
  274. type MetadataOverride<T> = {
  275. add?: Partial<T>;
  276. remove?: Partial<T>;
  277. set?: Partial<T>;
  278. };
  279. /**
  280. * An abstract class for inserting the root test component element in a platform independent way.
  281. *
  282. * @publicApi
  283. */
  284. declare class TestComponentRenderer {
  285. insertRootElement(rootElementId: string): void;
  286. removeAllRootElements?(): void;
  287. }
  288. /**
  289. * @publicApi
  290. */
  291. declare const ComponentFixtureAutoDetect: InjectionToken<boolean>;
  292. /**
  293. * @publicApi
  294. */
  295. declare const ComponentFixtureNoNgZone: InjectionToken<boolean>;
  296. /**
  297. * @publicApi
  298. */
  299. interface TestModuleMetadata {
  300. providers?: any[];
  301. declarations?: any[];
  302. imports?: any[];
  303. schemas?: Array<SchemaMetadata | any[]>;
  304. teardown?: ModuleTeardownOptions;
  305. /**
  306. * Whether NG0304 runtime errors should be thrown when unknown elements are present in component's
  307. * template. Defaults to `false`, where the error is simply logged. If set to `true`, the error is
  308. * thrown.
  309. * @see [NG8001](/errors/NG8001) for the description of the problem and how to fix it
  310. */
  311. errorOnUnknownElements?: boolean;
  312. /**
  313. * Whether errors should be thrown when unknown properties are present in component's template.
  314. * Defaults to `false`, where the error is simply logged.
  315. * If set to `true`, the error is thrown.
  316. * @see [NG8002](/errors/NG8002) for the description of the error and how to fix it
  317. */
  318. errorOnUnknownProperties?: boolean;
  319. /**
  320. * Whether errors that happen during application change detection should be rethrown.
  321. *
  322. * When `true`, errors that are caught during application change detection will
  323. * be reported to the `ErrorHandler` and rethrown to prevent them from going
  324. * unnoticed in tests.
  325. *
  326. * When `false`, errors are only forwarded to the `ErrorHandler`, which by default
  327. * simply logs them to the console.
  328. *
  329. * Defaults to `true`.
  330. */
  331. rethrowApplicationErrors?: boolean;
  332. /**
  333. * Whether defer blocks should behave with manual triggering or play through normally.
  334. * Defaults to `manual`.
  335. */
  336. deferBlockBehavior?: DeferBlockBehavior;
  337. }
  338. /**
  339. * @publicApi
  340. */
  341. interface TestEnvironmentOptions {
  342. /**
  343. * Configures the test module teardown behavior in `TestBed`.
  344. */
  345. teardown?: ModuleTeardownOptions;
  346. /**
  347. * Whether errors should be thrown when unknown elements are present in component's template.
  348. * Defaults to `false`, where the error is simply logged.
  349. * If set to `true`, the error is thrown.
  350. * @see [NG8001](/errors/NG8001) for the description of the error and how to fix it
  351. */
  352. errorOnUnknownElements?: boolean;
  353. /**
  354. * Whether errors should be thrown when unknown properties are present in component's template.
  355. * Defaults to `false`, where the error is simply logged.
  356. * If set to `true`, the error is thrown.
  357. * @see [NG8002](/errors/NG8002) for the description of the error and how to fix it
  358. */
  359. errorOnUnknownProperties?: boolean;
  360. }
  361. /**
  362. * Configures the test module teardown behavior in `TestBed`.
  363. * @publicApi
  364. */
  365. interface ModuleTeardownOptions {
  366. /** Whether the test module should be destroyed after every test. Defaults to `true`. */
  367. destroyAfterEach: boolean;
  368. /** Whether errors during test module destruction should be re-thrown. Defaults to `true`. */
  369. rethrowErrors?: boolean;
  370. }
  371. /**
  372. * Static methods implemented by the `TestBed`.
  373. *
  374. * @publicApi
  375. */
  376. interface TestBedStatic extends TestBed {
  377. new (...args: any[]): TestBed;
  378. }
  379. /**
  380. * Options that can be configured for a test component.
  381. *
  382. * @publicApi
  383. */
  384. interface TestComponentOptions {
  385. /** Bindings to apply to the test component. */
  386. bindings?: Binding[];
  387. }
  388. /**
  389. * Returns a singleton of the `TestBed` class.
  390. *
  391. * @publicApi
  392. */
  393. declare function getTestBed(): TestBed;
  394. /**
  395. * @publicApi
  396. */
  397. interface TestBed {
  398. get platform(): PlatformRef;
  399. get ngModule(): Type<any> | Type<any>[];
  400. /**
  401. * Initialize the environment for testing with a compiler factory, a PlatformRef, and an
  402. * angular module. These are common to every test in the suite.
  403. *
  404. * This may only be called once, to set up the common providers for the current test
  405. * suite on the current platform. If you absolutely need to change the providers,
  406. * first use `resetTestEnvironment`.
  407. *
  408. * Test modules and platforms for individual platforms are available from
  409. * '@angular/<platform_name>/testing'.
  410. */
  411. initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, options?: TestEnvironmentOptions): void;
  412. /**
  413. * Reset the providers for the test injector.
  414. */
  415. resetTestEnvironment(): void;
  416. resetTestingModule(): TestBed;
  417. configureCompiler(config: {
  418. providers?: any[];
  419. useJit?: boolean;
  420. }): void;
  421. configureTestingModule(moduleDef: TestModuleMetadata): TestBed;
  422. compileComponents(): Promise<any>;
  423. inject<T>(token: ProviderToken<T>, notFoundValue: undefined, options: InjectOptions & {
  424. optional?: false;
  425. }): T;
  426. inject<T>(token: ProviderToken<T>, notFoundValue: null | undefined, options: InjectOptions): T | null;
  427. inject<T>(token: ProviderToken<T>, notFoundValue?: T, options?: InjectOptions): T;
  428. /**
  429. * Runs the given function in the `EnvironmentInjector` context of `TestBed`.
  430. *
  431. * @see {@link https://angular.dev/api/core/EnvironmentInjector#runInContext}
  432. */
  433. runInInjectionContext<T>(fn: () => T): T;
  434. execute(tokens: any[], fn: Function, context?: any): any;
  435. overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBed;
  436. overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBed;
  437. overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBed;
  438. overridePipe(pipe: Type<any>, override: MetadataOverride<Pipe>): TestBed;
  439. overrideTemplate(component: Type<any>, template: string): TestBed;
  440. /**
  441. * Overwrites all providers for the given token with the given provider definition.
  442. */
  443. overrideProvider(token: any, provider: {
  444. useFactory: Function;
  445. deps: any[];
  446. multi?: boolean;
  447. }): TestBed;
  448. overrideProvider(token: any, provider: {
  449. useValue: any;
  450. multi?: boolean;
  451. }): TestBed;
  452. overrideProvider(token: any, provider: {
  453. useFactory?: Function;
  454. useValue?: any;
  455. deps?: any[];
  456. multi?: boolean;
  457. }): TestBed;
  458. overrideTemplateUsingTestingModule(component: Type<any>, template: string): TestBed;
  459. createComponent<T>(component: Type<T>, options?: TestComponentOptions): ComponentFixture<T>;
  460. /**
  461. * Execute any pending effects.
  462. *
  463. * @deprecated use `TestBed.tick()` instead
  464. */
  465. flushEffects(): void;
  466. /**
  467. * Execute any pending work required to synchronize model to the UI.
  468. *
  469. * @publicApi 20.0
  470. */
  471. tick(): void;
  472. }
  473. /**
  474. * @description
  475. * Configures and initializes environment for unit testing and provides methods for
  476. * creating components and services in unit tests.
  477. *
  478. * `TestBed` is the primary api for writing unit tests for Angular applications and libraries.
  479. *
  480. * @publicApi
  481. */
  482. declare const TestBed: TestBedStatic;
  483. /**
  484. * Allows injecting dependencies in `beforeEach()` and `it()`. Note: this function
  485. * (imported from the `@angular/core/testing` package) can **only** be used to inject dependencies
  486. * in tests. To inject dependencies in your application code, use the [`inject`](api/core/inject)
  487. * function from the `@angular/core` package instead.
  488. *
  489. * Example:
  490. *
  491. * ```ts
  492. * beforeEach(inject([Dependency, AClass], (dep, object) => {
  493. * // some code that uses `dep` and `object`
  494. * // ...
  495. * }));
  496. *
  497. * it('...', inject([AClass], (object) => {
  498. * object.doSomething();
  499. * expect(...);
  500. * })
  501. * ```
  502. *
  503. * @publicApi
  504. */
  505. declare function inject(tokens: any[], fn: Function): () => any;
  506. /**
  507. * @publicApi
  508. */
  509. declare class InjectSetupWrapper {
  510. private _moduleDef;
  511. constructor(_moduleDef: () => TestModuleMetadata);
  512. private _addModule;
  513. inject(tokens: any[], fn: Function): () => any;
  514. }
  515. /**
  516. * @publicApi
  517. */
  518. declare function withModule(moduleDef: TestModuleMetadata): InjectSetupWrapper;
  519. declare function withModule(moduleDef: TestModuleMetadata, fn: Function): () => any;
  520. declare class MetadataOverrider {
  521. private _references;
  522. /**
  523. * Creates a new instance for the given metadata class
  524. * based on an old instance and overrides.
  525. */
  526. overrideMetadata<C extends T, T>(metadataClass: {
  527. new (options: T): C;
  528. }, oldMetadata: C, override: MetadataOverride<T>): C;
  529. }
  530. /**
  531. * Fake implementation of user agent history and navigation behavior. This is a
  532. * high-fidelity implementation of browser behavior that attempts to emulate
  533. * things like traversal delay.
  534. */
  535. declare class FakeNavigation implements Navigation {
  536. /**
  537. * The fake implementation of an entries array. Only same-document entries
  538. * allowed.
  539. */
  540. private readonly entriesArr;
  541. /**
  542. * The current active entry index into `entriesArr`.
  543. */
  544. private currentEntryIndex;
  545. /**
  546. * A Map of pending traversals, so that traversals to the same entry can be
  547. * re-used.
  548. */
  549. private readonly traversalQueue;
  550. /**
  551. * A Promise that resolves when the previous traversals have finished. Used to
  552. * simulate the cross-process communication necessary for traversals.
  553. */
  554. private nextTraversal;
  555. /**
  556. * A prospective current active entry index, which includes unresolved
  557. * traversals. Used by `go` to determine where navigations are intended to go.
  558. */
  559. private prospectiveEntryIndex;
  560. /**
  561. * A test-only option to make traversals synchronous, rather than emulate
  562. * cross-process communication.
  563. */
  564. private synchronousTraversals;
  565. /** Whether to allow a call to setInitialEntryForTesting. */
  566. private canSetInitialEntry;
  567. /** The next unique id for created entries. Replace recreates this id. */
  568. private nextId;
  569. /** The next unique key for created entries. Replace inherits this id. */
  570. private nextKey;
  571. /** Whether this fake is disposed. */
  572. private disposed;
  573. /** Equivalent to `navigation.currentEntry`. */
  574. get currentEntry(): FakeNavigationHistoryEntry;
  575. get canGoBack(): boolean;
  576. get canGoForward(): boolean;
  577. private readonly createEventTarget;
  578. private readonly _window;
  579. get window(): Pick<Window, 'addEventListener' | 'removeEventListener'>;
  580. constructor(doc: Document, startURL: `http${string}`);
  581. /**
  582. * Sets the initial entry.
  583. */
  584. setInitialEntryForTesting(url: `http${string}`, options?: {
  585. historyState: unknown;
  586. state?: unknown;
  587. }): void;
  588. /** Returns whether the initial entry is still eligible to be set. */
  589. canSetInitialEntryForTesting(): boolean;
  590. /**
  591. * Sets whether to emulate traversals as synchronous rather than
  592. * asynchronous.
  593. */
  594. setSynchronousTraversalsForTesting(synchronousTraversals: boolean): void;
  595. /** Equivalent to `navigation.entries()`. */
  596. entries(): FakeNavigationHistoryEntry[];
  597. /** Equivalent to `navigation.navigate()`. */
  598. navigate(url: string, options?: NavigationNavigateOptions): FakeNavigationResult;
  599. /** Equivalent to `history.pushState()`. */
  600. pushState(data: unknown, title: string, url?: string): void;
  601. /** Equivalent to `history.replaceState()`. */
  602. replaceState(data: unknown, title: string, url?: string): void;
  603. private pushOrReplaceState;
  604. /** Equivalent to `navigation.traverseTo()`. */
  605. traverseTo(key: string, options?: NavigationOptions): FakeNavigationResult;
  606. /** Equivalent to `navigation.back()`. */
  607. back(options?: NavigationOptions): FakeNavigationResult;
  608. /** Equivalent to `navigation.forward()`. */
  609. forward(options?: NavigationOptions): FakeNavigationResult;
  610. /**
  611. * Equivalent to `history.go()`.
  612. * Note that this method does not actually work precisely to how Chrome
  613. * does, instead choosing a simpler model with less unexpected behavior.
  614. * Chrome has a few edge case optimizations, for instance with repeated
  615. * `back(); forward()` chains it collapses certain traversals.
  616. */
  617. go(direction: number): void;
  618. /** Runs a traversal synchronously or asynchronously */
  619. private runTraversal;
  620. /** Equivalent to `navigation.addEventListener()`. */
  621. addEventListener(type: string, callback: EventListenerOrEventListenerObject, options?: AddEventListenerOptions | boolean): void;
  622. /** Equivalent to `navigation.removeEventListener()`. */
  623. removeEventListener(type: string, callback: EventListenerOrEventListenerObject, options?: EventListenerOptions | boolean): void;
  624. /** Equivalent to `navigation.dispatchEvent()` */
  625. dispatchEvent(event: Event): boolean;
  626. /** Cleans up resources. */
  627. dispose(): void;
  628. /** Returns whether this fake is disposed. */
  629. isDisposed(): boolean;
  630. abortOngoingNavigation(eventToAbort: InternalFakeNavigateEvent, reason?: Error): void;
  631. /**
  632. * Implementation for all navigations and traversals.
  633. * @returns true if the event was intercepted, otherwise false
  634. */
  635. private userAgentNavigate;
  636. /** Utility method for finding entries with the given `key`. */
  637. private findEntry;
  638. set onnavigate(_handler: ((this: Navigation, ev: NavigateEvent) => any) | null);
  639. get onnavigate(): ((this: Navigation, ev: NavigateEvent) => any) | null;
  640. set oncurrententrychange(_handler: // tslint:disable-next-line:no-any
  641. ((this: Navigation, ev: NavigationCurrentEntryChangeEvent) => any) | null);
  642. get oncurrententrychange(): // tslint:disable-next-line:no-any
  643. ((this: Navigation, ev: NavigationCurrentEntryChangeEvent) => any) | null;
  644. set onnavigatesuccess(_handler: ((this: Navigation, ev: Event) => any) | null);
  645. get onnavigatesuccess(): ((this: Navigation, ev: Event) => any) | null;
  646. set onnavigateerror(_handler: ((this: Navigation, ev: ErrorEvent) => any) | null);
  647. get onnavigateerror(): ((this: Navigation, ev: ErrorEvent) => any) | null;
  648. private _transition;
  649. get transition(): NavigationTransition | null;
  650. updateCurrentEntry(_options: NavigationUpdateCurrentEntryOptions): void;
  651. reload(_options?: NavigationReloadOptions): NavigationResult;
  652. }
  653. /**
  654. * Fake equivalent of the `NavigationResult` interface with
  655. * `FakeNavigationHistoryEntry`.
  656. */
  657. interface FakeNavigationResult extends NavigationResult {
  658. readonly committed: Promise<FakeNavigationHistoryEntry>;
  659. readonly finished: Promise<FakeNavigationHistoryEntry>;
  660. }
  661. /**
  662. * Fake equivalent of `NavigationHistoryEntry`.
  663. */
  664. declare class FakeNavigationHistoryEntry implements NavigationHistoryEntry {
  665. private eventTarget;
  666. readonly url: string | null;
  667. readonly sameDocument: boolean;
  668. readonly id: string;
  669. readonly key: string;
  670. readonly index: number;
  671. private readonly state;
  672. private readonly historyState;
  673. ondispose: ((this: NavigationHistoryEntry, ev: Event) => any) | null;
  674. constructor(eventTarget: EventTarget, url: string | null, { id, key, index, sameDocument, state, historyState, }: {
  675. id: string;
  676. key: string;
  677. index: number;
  678. sameDocument: boolean;
  679. historyState: unknown;
  680. state?: unknown;
  681. });
  682. getState(): unknown;
  683. getHistoryState(): unknown;
  684. addEventListener(type: string, callback: EventListenerOrEventListenerObject, options?: AddEventListenerOptions | boolean): void;
  685. removeEventListener(type: string, callback: EventListenerOrEventListenerObject, options?: EventListenerOptions | boolean): void;
  686. dispatchEvent(event: Event): boolean;
  687. /** internal */
  688. dispose(): void;
  689. }
  690. /** `NavigationInterceptOptions` with experimental commit option. */
  691. interface ExperimentalNavigationInterceptOptions extends NavigationInterceptOptions {
  692. precommitHandler?: (controller: NavigationPrecommitController) => Promise<void>;
  693. }
  694. interface NavigationPrecommitController {
  695. redirect: (url: string, options?: NavigationNavigateOptions) => void;
  696. }
  697. interface ExperimentalNavigateEvent extends NavigateEvent {
  698. intercept(options?: ExperimentalNavigationInterceptOptions): void;
  699. precommitHandler?: () => Promise<void>;
  700. }
  701. /**
  702. * Fake equivalent of `NavigateEvent`.
  703. */
  704. interface FakeNavigateEvent extends ExperimentalNavigateEvent {
  705. readonly destination: FakeNavigationDestination;
  706. }
  707. interface InternalFakeNavigateEvent extends FakeNavigateEvent {
  708. readonly sameDocument: boolean;
  709. readonly result: InternalNavigationResult;
  710. interceptionState: 'none' | 'intercepted' | 'committed' | 'scrolled' | 'finished';
  711. scrollBehavior: 'after-transition' | 'manual' | null;
  712. focusResetBehavior: 'after-transition' | 'manual' | null;
  713. abortController: AbortController;
  714. cancel(reason: Error): void;
  715. }
  716. /**
  717. * Fake equivalent of `NavigationDestination`.
  718. */
  719. declare class FakeNavigationDestination implements NavigationDestination {
  720. url: string;
  721. readonly sameDocument: boolean;
  722. readonly key: string | null;
  723. readonly id: string | null;
  724. readonly index: number;
  725. state?: unknown;
  726. private readonly historyState;
  727. constructor({ url, sameDocument, historyState, state, key, id, index, }: {
  728. url: string;
  729. sameDocument: boolean;
  730. historyState: unknown;
  731. state?: unknown;
  732. key?: string | null;
  733. id?: string | null;
  734. index?: number;
  735. });
  736. getState(): unknown;
  737. getHistoryState(): unknown;
  738. }
  739. /**
  740. * Internal utility class for representing the result of a navigation.
  741. * Generally equivalent to the "apiMethodTracker" in the spec.
  742. */
  743. declare class InternalNavigationResult {
  744. readonly navigation: FakeNavigation;
  745. committedTo: FakeNavigationHistoryEntry | null;
  746. committedResolve: (entry: FakeNavigationHistoryEntry) => void;
  747. committedReject: (reason: Error) => void;
  748. finishedResolve: () => void;
  749. finishedReject: (reason: Error) => void;
  750. readonly committed: Promise<FakeNavigationHistoryEntry>;
  751. readonly finished: Promise<FakeNavigationHistoryEntry>;
  752. get signal(): AbortSignal;
  753. private readonly abortController;
  754. constructor(navigation: FakeNavigation);
  755. }
  756. declare function getCleanupHook(expectedTeardownValue: boolean): VoidFunction;
  757. declare class Log<T = string> {
  758. logItems: T[];
  759. constructor();
  760. add(value: T): void;
  761. fn(value: T): () => void;
  762. clear(): void;
  763. result(): string;
  764. static ɵfac: i0.ɵɵFactoryDeclaration<Log<any>, never>;
  765. static ɵprov: i0.ɵɵInjectableDeclaration<Log<any>>;
  766. }
  767. export { ComponentFixture, ComponentFixtureAutoDetect, ComponentFixtureNoNgZone, DeferBlockBehavior, DeferBlockFixture, DeferBlockState, InjectSetupWrapper, TestBed, TestComponentRenderer, discardPeriodicTasks, fakeAsync, flush, flushMicrotasks, getTestBed, inject, resetFakeAsyncZone, tick, waitForAsync, withModule, FakeNavigation as ɵFakeNavigation, Log as ɵLog, MetadataOverrider as ɵMetadataOverrider, getCleanupHook as ɵgetCleanupHook };
  768. export type { MetadataOverride, ModuleTeardownOptions, TestBedStatic, TestComponentOptions, TestEnvironmentOptions, TestModuleMetadata };