UNPKG

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