index.d.ts 26 KB

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