Skip to content

Commit

Permalink
Make it easier to mock for server usage
Browse files Browse the repository at this point in the history
  • Loading branch information
JAForbes committed Apr 27, 2024
1 parent 7f53613 commit 86a0683
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/index.ts
@@ -1,6 +1,17 @@
export type Window = typeof window
export type Location = typeof window.location
export type History = typeof window.history
export type Window = {
location: Location,
history: History,
addEventListener(type: 'popstate', listener: (e: PopStateEvent) => void): void
removeEventListener(type: 'popstate', listener: (e: PopStateEvent) => void): void
}
export type Location = {
pathname: string
}
export type History = {
replaceState(data: any, title: string, url: string): void
pushState(data: any, title: string, url: string): void
back(): void
}

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

Expand Down Expand Up @@ -57,7 +68,7 @@ export function joinPath(a:string,b: string): string {
}

function Superhistory({
_window = globalThis.window,
_window= globalThis.window as any as Window,
onChange = () => {},
}: Attrs = {}): InternalInstance {
const children = new Set<InternalInstance>()
Expand All @@ -78,7 +89,8 @@ function Superhistory({

function go(path: string, options: { replace?: boolean } = {}) {
path = normalizePath(path)
_window.history[`${options.replace ? 'replace' : 'push'}State`](

_window.history[options.replace ? 'replaceState' : 'pushState'](
null,
'',
path,
Expand Down

0 comments on commit 86a0683

Please sign in to comment.