UNPKG

houser-js-utils

Version:

A comprehensive collection of TypeScript utility functions for common development tasks including array manipulation, string processing, date handling, random number generation, validation, and much more.

142 lines (141 loc) 4.82 kB
/** * @module TestUtils * @description A collection of utility functions for testing, mocking, and test data generation. * @example * ```typescript * import { TestUtils } from 'houser-js-utils'; * * // Generate test data * const testUser = TestUtils.createTestDataGenerator({ name: 'John', age: 30 }); * * // Create mock function * const mockFn = TestUtils.createMock(); * * // Wait for async operations * await TestUtils.waitFor(() => element.isVisible()); * ``` */ export declare const TestUtils: { /** * Creates a test animation event * @param type - Event type * @param options - Event options * @returns Test animation event */ createTestAnimationEvent(type: string, options?: AnimationEventInit): AnimationEvent; /** * Creates a test clipboard event * @param type - Event type * @param options - Event options * @returns Test clipboard event */ createTestClipboardEvent(type: string, options?: ClipboardEventInit): ClipboardEvent; /** * Creates a test data array generator * @param template - Template object * @returns Function that generates an array of test data */ createTestDataArrayGenerator<T extends object>(template: T): (count: number, overrides?: Partial<T>) => T[]; /** * Creates a test data generator * @param template - Template object * @returns Function that generates test data */ createTestDataGenerator<T extends object>(template: T): (overrides?: Partial<T>) => T; /** * Creates a test drag event * @param type - Event type * @param options - Event options * @returns Test drag event */ createTestDragEvent(type: string, options?: DragEventInit): DragEvent; /** * Creates a test event * @param type - Event type * @param options - Event options * @returns Test event */ createTestEvent(type: string, options?: EventInit): Event; /** * Creates a test focus event * @param type - Event type * @param options - Event options * @returns Test focus event */ createTestFocusEvent(type: string, options?: FocusEventInit): FocusEvent; /** * Creates a test input event * @param type - Event type * @param options - Event options * @returns Test input event */ createTestInputEvent(type: string, options?: InputEventInit): InputEvent; /** * Creates a test keyboard event * @param type - Event type * @param options - Event options * @returns Test keyboard event */ createTestKeyboardEvent(type: string, options?: KeyboardEventInit): KeyboardEvent; /** * Creates a test mouse event * @param type - Event type * @param options - Event options * @returns Test mouse event */ createTestMouseEvent(type: string, options?: MouseEventInit): MouseEvent; /** * Creates a test touch event * @param type - Event type * @param options - Event options * @returns Test touch event */ createTestTouchEvent(type: string, options?: TouchEventInit): TouchEvent; /** * Creates a test transition event * @param type - Event type * @param options - Event options * @returns Test transition event */ createTestTransitionEvent(type: string, options?: TransitionEventInit): TransitionEvent; /** * Creates a mock error promise * @param error - Error to reject with * @param delay - Delay in milliseconds * @returns Mock error promise */ createMockErrorPromise(error: Error, delay?: number): Promise<never>; /** * Creates a mock function * @param implementation - Optional implementation function * @returns Mock function */ createMock<T extends (...args: any[]) => any>(implementation?: T): T; /** * Creates a mock object * @param template - Template object to mock * @returns Mock object */ createMockObject<T extends object>(template: T): T; /** * Creates a mock promise * @param value - Value to resolve with * @param delay - Delay in milliseconds * @returns Mock promise */ createMockPromise<T>(value: T, delay?: number): Promise<T>; /** * Waits for a number of milliseconds * @param ms - Milliseconds to wait * @returns Promise that resolves after the delay */ wait(ms: number): Promise<void>; /** * Waits for a condition to be true * @param condition - Function that returns a boolean * @param timeout - Timeout in milliseconds * @param interval - Check interval in milliseconds * @returns Promise that resolves when condition is true */ waitFor(condition: () => boolean, timeout?: number, interval?: number): Promise<void>; };