/** * Test utilities for SupaStory SDK * * These utilities help you test your application's integration with * the SupaStory SDK without making actual network requests. * * @example * import { createMockSDK, createMockConfig } from '@supastory/capture-sdk/testing'; * * describe('MyComponent', () => { * it('should initialize SupaStory', () => { * const mock = createMockSDK(); * mock.init(createMockConfig()); * expect(mock.isRecording()).toBe(true); * }); * }); */ import type { LogLevel, SDKConfig, SDKError, SDKStatus } from './types/events'; /** * Mock SDK interface matching the real SDK API */ export interface MockSDK { init: (config: SDKConfig) => void; start: () => void; stop: () => void; pause: () => void; resume: () => void; getSessionId: () => string | null; isRecording: () => boolean; getStatus: () => SDKStatus; identify: (userId: string, traits?: Record) => void; setLogLevel: (level: LogLevel) => void; _getCallHistory: () => MockCallHistory; _getErrors: () => SDKError[]; _reset: () => void; _simulateError: (error: SDKError) => void; } /** * History of SDK method calls for test assertions */ export interface MockCallHistory { init: SDKConfig[]; start: number; stop: number; pause: number; resume: number; identify: Array<{ userId: string; traits?: Record; }>; setLogLevel: LogLevel[]; } /** * Creates a mock SDK instance for testing * * The mock SDK tracks all method calls and simulates basic state * without making network requests or capturing real events. * * @returns Mock SDK instance with additional test utilities * * @example * const mock = createMockSDK(); * * // Use like real SDK * mock.init({ projectKey: 'test_key' }); * mock.identify('user_123'); * * // Assert on calls * const history = mock._getCallHistory(); * expect(history.init).toHaveLength(1); * expect(history.identify[0].userId).toBe('user_123'); */ export declare function createMockSDK(): MockSDK; /** * Creates a valid mock configuration for testing * * @param overrides - Optional config overrides * @returns Valid SDK configuration * * @example * const config = createMockConfig({ sampleRate: 0.5 }); */ export declare function createMockConfig(overrides?: Partial): SDKConfig; /** * Creates a mock error callback that captures errors * * @returns Object with callback function and captured errors * * @example * const errorCapture = createErrorCapture(); * mock.init({ ...config, onError: errorCapture.callback }); * * // Trigger an error... * * expect(errorCapture.errors).toHaveLength(1); * expect(errorCapture.errors[0].code).toBe('NETWORK_ERROR'); */ export declare function createErrorCapture(): { callback: (error: SDKError) => void; errors: SDKError[]; clear: () => void; }; /** * Creates a mock ready callback that captures session IDs * * @returns Object with callback function and captured session IDs * * @example * const readyCapture = createReadyCapture(); * mock.init({ ...config, onReady: readyCapture.callback }); * * expect(readyCapture.sessionIds).toHaveLength(1); */ export declare function createReadyCapture(): { callback: (sessionId: string) => void; sessionIds: string[]; clear: () => void; };