Skip to content

Commit 86a0683

Browse files
committed
Make it easier to mock for server usage
1 parent 7f53613 commit 86a0683

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lib/index.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
1-
export type Window = typeof window
2-
export type Location = typeof window.location
3-
export type History = typeof window.history
1+
export type Window = {
2+
location: Location,
3+
history: History,
4+
addEventListener(type: 'popstate', listener: (e: PopStateEvent) => void): void
5+
removeEventListener(type: 'popstate', listener: (e: PopStateEvent) => void): void
6+
}
7+
export type Location = {
8+
pathname: string
9+
}
10+
export type History = {
11+
replaceState(data: any, title: string, url: string): void
12+
pushState(data: any, title: string, url: string): void
13+
back(): void
14+
}
415

516
export type State = { path?: string, fullPath?: string }
617

@@ -57,7 +68,7 @@ export function joinPath(a:string,b: string): string {
5768
}
5869

5970
function Superhistory({
60-
_window = globalThis.window,
71+
_window= globalThis.window as any as Window,
6172
onChange = () => {},
6273
}: Attrs = {}): InternalInstance {
6374
const children = new Set<InternalInstance>()
@@ -78,7 +89,8 @@ function Superhistory({
7889

7990
function go(path: string, options: { replace?: boolean } = {}) {
8091
path = normalizePath(path)
81-
_window.history[`${options.replace ? 'replace' : 'push'}State`](
92+
93+
_window.history[options.replace ? 'replaceState' : 'pushState'](
8294
null,
8395
'',
8496
path,

0 commit comments

Comments
 (0)