index.d.ts 5.1 KB

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