@jam.dev/recording-links
Version:
Capture bug reports from your users with the Jam recording links SDK
79 lines • 2.7 kB
TypeScript
import { vi } from "vitest";
/**
* Shared browser mocking utilities for consistent test environment setup.
* This consolidates duplicate browser mock implementations across test files.
*/
export interface MockLocalStorage {
getItem: ReturnType<typeof vi.fn>;
setItem: ReturnType<typeof vi.fn>;
removeItem: ReturnType<typeof vi.fn>;
clear: ReturnType<typeof vi.fn>;
length: number;
key: ReturnType<typeof vi.fn>;
_store: Record<string, string>;
}
export declare const createMockLocalStorage: () => MockLocalStorage;
export interface MockHistory {
pushState: ReturnType<typeof vi.fn>;
replaceState: ReturnType<typeof vi.fn>;
}
export declare const createMockHistory: () => MockHistory;
export interface MockWindow {
localStorage: MockLocalStorage;
location: {
href: string;
};
addEventListener: ReturnType<typeof vi.fn>;
removeEventListener: ReturnType<typeof vi.fn>;
history: MockHistory;
}
export declare const createMockWindow: (initialUrl?: string) => MockWindow;
export declare class MockPopStateEvent {
type: string;
constructor(type: string, options?: PopStateEventInit);
state: any;
}
export declare class MockCustomEvent {
type: string;
options: {
detail?: any;
};
constructor(type: string, options?: {
detail?: any;
});
detail: any;
}
export declare class MockEventTarget {
private listeners;
addEventListener(type: string, listener: EventListener, options?: boolean | AddEventListenerOptions): void;
removeEventListener(type: string, listener: EventListener, options?: boolean | AddEventListenerOptions): void;
dispatchEvent(event: CustomEvent): boolean;
}
/**
* Complete browser environment mock setup
*/
export interface BrowserMocks {
localStorage: MockLocalStorage;
window: MockWindow;
history: MockHistory;
resetMocks: () => void;
}
export declare const createBrowserMocks: (initialUrl?: string) => BrowserMocks;
/**
* Helper to set test URL with parameters
*/
export declare const setTestUrl: (params?: Record<string, string>, baseUrl?: string) => string;
/**
* Helper to create mock RefCounter for tests
*/
export declare const createMockRefCounter: (count?: number) => {
count: number;
update: import("vitest").Mock<(...args: any[]) => any>;
addEventListener: import("vitest").Mock<(...args: any[]) => any>;
removeEventListener: import("vitest").Mock<(...args: any[]) => any>;
};
/**
* Browser environment setup helper that combines environment reset with mock creation
*/
export declare const setupBrowserEnvironment: (initialUrl?: string) => MockHistory;
//# sourceMappingURL=browser-mocks.d.ts.map