index.d.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /**
  2. * @license Angular v19.2.13
  3. * (c) 2010-2025 Google LLC. https://angular.io/
  4. * License: MIT
  5. */
  6. import * as i0 from '@angular/core';
  7. import { Provider, InjectionToken } from '@angular/core';
  8. export { ɵFakeNavigation } from '@angular/core/testing';
  9. import { Location, LocationStrategy } from '@angular/common';
  10. import { SubscriptionLike } from 'rxjs';
  11. import { PlatformLocation, LocationChangeListener } from '../platform_location.d-Lbv6Ueec.js';
  12. /**
  13. * Return a provider for the `FakeNavigation` in place of the real Navigation API.
  14. */
  15. declare function provideFakePlatformNavigation(): Provider[];
  16. /**
  17. * A spy for {@link Location} that allows tests to fire simulated location events.
  18. *
  19. * @publicApi
  20. */
  21. declare class SpyLocation implements Location {
  22. urlChanges: string[];
  23. private _history;
  24. private _historyIndex;
  25. /** @docs-private */
  26. ngOnDestroy(): void;
  27. setInitialPath(url: string): void;
  28. setBaseHref(url: string): void;
  29. path(): string;
  30. getState(): unknown;
  31. isCurrentPathEqualTo(path: string, query?: string): boolean;
  32. simulateUrlPop(pathname: string): void;
  33. simulateHashChange(pathname: string): void;
  34. prepareExternalUrl(url: string): string;
  35. go(path: string, query?: string, state?: any): void;
  36. replaceState(path: string, query?: string, state?: any): void;
  37. forward(): void;
  38. back(): void;
  39. historyGo(relativePosition?: number): void;
  40. onUrlChange(fn: (url: string, state: unknown) => void): VoidFunction;
  41. subscribe(onNext: (value: any) => void, onThrow?: ((error: any) => void) | null, onReturn?: (() => void) | null): SubscriptionLike;
  42. normalize(url: string): string;
  43. private pushHistory;
  44. static ɵfac: i0.ɵɵFactoryDeclaration<SpyLocation, never>;
  45. static ɵprov: i0.ɵɵInjectableDeclaration<SpyLocation>;
  46. }
  47. /**
  48. * A mock implementation of {@link LocationStrategy} that allows tests to fire simulated
  49. * location events.
  50. *
  51. * @publicApi
  52. */
  53. declare class MockLocationStrategy extends LocationStrategy {
  54. internalBaseHref: string;
  55. internalPath: string;
  56. internalTitle: string;
  57. urlChanges: string[];
  58. private stateChanges;
  59. constructor();
  60. simulatePopState(url: string): void;
  61. path(includeHash?: boolean): string;
  62. prepareExternalUrl(internal: string): string;
  63. pushState(ctx: any, title: string, path: string, query: string): void;
  64. replaceState(ctx: any, title: string, path: string, query: string): void;
  65. onPopState(fn: (value: any) => void): void;
  66. getBaseHref(): string;
  67. back(): void;
  68. forward(): void;
  69. getState(): unknown;
  70. static ɵfac: i0.ɵɵFactoryDeclaration<MockLocationStrategy, never>;
  71. static ɵprov: i0.ɵɵInjectableDeclaration<MockLocationStrategy>;
  72. }
  73. /**
  74. * Mock platform location config
  75. *
  76. * @publicApi
  77. */
  78. interface MockPlatformLocationConfig {
  79. startUrl?: string;
  80. appBaseHref?: string;
  81. }
  82. /**
  83. * Provider for mock platform location config
  84. *
  85. * @publicApi
  86. */
  87. declare const MOCK_PLATFORM_LOCATION_CONFIG: InjectionToken<MockPlatformLocationConfig>;
  88. /**
  89. * Mock implementation of URL state.
  90. *
  91. * @publicApi
  92. */
  93. declare class MockPlatformLocation implements PlatformLocation {
  94. private baseHref;
  95. private hashUpdate;
  96. private popStateSubject;
  97. private urlChangeIndex;
  98. private urlChanges;
  99. constructor(config?: MockPlatformLocationConfig);
  100. get hostname(): string;
  101. get protocol(): string;
  102. get port(): string;
  103. get pathname(): string;
  104. get search(): string;
  105. get hash(): string;
  106. get state(): unknown;
  107. getBaseHrefFromDOM(): string;
  108. onPopState(fn: LocationChangeListener): VoidFunction;
  109. onHashChange(fn: LocationChangeListener): VoidFunction;
  110. get href(): string;
  111. get url(): string;
  112. private parseChanges;
  113. replaceState(state: any, title: string, newUrl: string): void;
  114. pushState(state: any, title: string, newUrl: string): void;
  115. forward(): void;
  116. back(): void;
  117. historyGo(relativePosition?: number): void;
  118. getState(): unknown;
  119. /**
  120. * Browsers are inconsistent in when they fire events and perform the state updates
  121. * The most easiest thing to do in our mock is synchronous and that happens to match
  122. * Firefox and Chrome, at least somewhat closely
  123. *
  124. * https://github.com/WICG/navigation-api#watching-for-navigations
  125. * https://docs.google.com/document/d/1Pdve-DJ1JCGilj9Yqf5HxRJyBKSel5owgOvUJqTauwU/edit#heading=h.3ye4v71wsz94
  126. * popstate is always sent before hashchange:
  127. * https://developer.mozilla.org/en-US/docs/Web/API/Window/popstate_event#when_popstate_is_sent
  128. */
  129. private emitEvents;
  130. static ɵfac: i0.ɵɵFactoryDeclaration<MockPlatformLocation, [{ optional: true; }]>;
  131. static ɵprov: i0.ɵɵInjectableDeclaration<MockPlatformLocation>;
  132. }
  133. /**
  134. * Returns mock providers for the `Location` and `LocationStrategy` classes.
  135. * The mocks are helpful in tests to fire simulated location events.
  136. *
  137. * @publicApi
  138. */
  139. declare function provideLocationMocks(): Provider[];
  140. export { MOCK_PLATFORM_LOCATION_CONFIG, MockLocationStrategy, MockPlatformLocation, SpyLocation, provideLocationMocks, provideFakePlatformNavigation as ɵprovideFakePlatformNavigation };
  141. export type { MockPlatformLocationConfig };