/** * bQuery Testing — 1.14+ extension helpers. * * Builds on the existing `renderComponent` / `flushEffects` / `fireEvent` / * `waitFor` primitives with: * * - Auto-cleanup tracking (`cleanup`, `autoCleanup`). * - Screen queries (`getByRole`, `getByText`, `getByTestId`, ...). * - `userEvent` namespace (composed real-user-style interactions). * - `fireEvent.*` shortcut methods. * - Reactive helpers (`mockComputed`, `mockEffect`, `tick`, `flushPromises`). * - Mocks (`mockStore`, `mockI18n`, `mockForm`, `mockFetch`, `mockWebSocket`). * - Snapshot / a11y helpers (`prettyDOM`, `expectAccessible`). * * Every helper is SSR-safe at import time (no top-level DOM access). * * @module bquery/testing */ import { type Signal } from '../reactive/index'; type Cleanable = { unmount: () => void; }; /** @internal — register a render result for {@link cleanup}. */ export declare const __trackMount: (result: Cleanable) => void; /** * Unmount every render result tracked since the last {@link cleanup} call. * * Safe to call repeatedly; idempotent when no mounts are pending. */ export declare const cleanup: () => void; /** * Install before/after hooks (compatible with `bun:test`) that run * {@link cleanup} after every test. */ export declare const autoCleanup: (beforeEach: (fn: () => void) => void, afterEach: (fn: () => void) => void) => void; /** Wait one microtask + flush effects. */ export declare const tick: () => Promise; /** Alias of {@link tick}. */ export declare const nextTick: () => Promise; /** * Drain micro- and macro-task queues, then flush reactive effects. */ export declare const flushPromises: () => Promise; /** * Synchronously run any frame-scheduled work (motion timelines, etc.). * In the default happy-dom environment this is a no-op + `flushEffects()`. */ export declare const runScheduled: () => void; /** * Higher-level interactions composed from {@link fireEvent}. Every action * flushes effects + microtasks before returning so consumers can `await` it. */ export declare const userEvent: { click(el: Element): Promise; dblClick(el: Element): Promise; hover(el: Element): Promise; unhover(el: Element): Promise; type(el: Element, text: string, opts?: { delay?: number; }): Promise; clear(el: Element): Promise; selectOptions(el: Element, values: string | string[]): Promise; tab(): Promise; paste(el: Element, text: string): Promise; }; /** * Bound query helpers returned by {@link within} and {@link screen}. */ export interface Queries { getByRole(role: string): Element; queryByRole(role: string): Element | null; findByRole(role: string, timeoutMs?: number): Promise; getByText(text: string | RegExp): Element; queryByText(text: string | RegExp): Element | null; findByText(text: string | RegExp, timeoutMs?: number): Promise; getByLabelText(label: string | RegExp): Element; queryByLabelText(label: string | RegExp): Element | null; findByLabelText(label: string | RegExp, timeoutMs?: number): Promise; getByPlaceholderText(text: string | RegExp): Element; queryByPlaceholderText(text: string | RegExp): Element | null; findByPlaceholderText(text: string | RegExp, timeoutMs?: number): Promise; getByTestId(id: string): Element; queryByTestId(id: string): Element | null; findByTestId(id: string, timeoutMs?: number): Promise; } /** * Build a scoped set of queries against the given root element. Shadow roots * encountered during traversal are searched recursively. */ export declare const within: (root: ParentNode) => Queries; /** * Document-scoped query helpers. Lazy: never touches `document` at import * time, so importing this module from an SSR context is safe. */ export declare const screen: Queries; /** Wrap {@link computed} with a `recomputeCount` counter. */ export declare const mockComputed: (fn: () => T) => { readonly value: T; peek(): T; recomputeCount: number; reset(): void; }; /** Wrap {@link effect} with a `runs` counter and `dispose` handle. */ export declare const mockEffect: (fn: () => void) => { runs: number; dispose: () => void; }; /** * Lightweight isolated store for tests. Not connected to the global store * registry. */ export interface MockStore> { readonly state: T; set(patch: Partial): void; reset(): void; readonly initialState: Readonly; } export declare const mockStore: >(initialState: T) => MockStore; /** * In-memory i18n harness. Returns a `t()` function and `setLocale` helper. */ export interface MockI18n { readonly locale: Signal; setLocale(locale: string): void; t(key: string, vars?: Record): string; } export declare const mockI18n: (opts?: { locale?: string; messages?: Record>; }) => MockI18n; /** * Minimal reactive form harness. Provides `values`, `errors`, `set`, `submit`. */ export interface MockForm> { readonly values: Signal; readonly errors: Signal>>; set(field: K, value: T[K]): void; setError(field: K, error: string | undefined): void; reset(): void; } export declare const mockForm: >(initialValues: T) => MockForm; /** * Minimal fetch mocker. Accepts a routes map and overrides `globalThis.fetch` * for the duration of the returned `restore()` lifetime. */ export interface MockFetchRoute { status?: number; headers?: Record; body?: unknown; } export declare const mockFetch: (routes: Record MockFetchRoute | Promise)>) => { restore: () => void; calls: Request[]; }; /** * Minimal in-memory WebSocket pair for driving `reactive/realtime` from tests. */ export interface MockWebSocket { readonly socket: { send(data: string): void; close(): void; readyState: number; onopen?: () => void; onmessage?: (event: { data: string; }) => void; onclose?: () => void; onerror?: (err: unknown) => void; }; /** Simulate a server-side message arriving. */ emit(data: string): void; /** Read messages the client sent. */ readonly sent: string[]; open(): void; close(): void; } export declare const mockWebSocket: () => MockWebSocket; /** * Render a pretty-printed HTML snapshot of an element, optionally trimming * very large output and traversing shadow roots. */ export declare const prettyDOM: (el: Element, opts?: { maxLength?: number; includeShadow?: boolean; }) => string; /** Quick reactive subtree summary used by debugging tests. */ export declare const getReactiveSummary: (el: Element) => { components: number; shadowRoots: number; testIds: string[]; }; /** * Lightweight a11y assertion: returns a structured result that callers can * combine with their assertion library. Looks for the most common defects * (missing alt text on images, missing form labels, missing button labels). */ export interface AccessibilityResult { readonly passed: boolean; readonly violations: readonly { rule: string; element: Element; message: string; }[]; } export declare const expectAccessible: (root: Element) => AccessibilityResult; export {}; //# sourceMappingURL=extensions.d.ts.map