/** * Testing utilities for bQuery.js. * * Provides helpers for mounting components, controlling signals, mocking * the router, dispatching events, and asserting async conditions — all * designed for use with `bun:test` and happy-dom. * * @module bquery/testing */ import type { FireEventOptions, MockRouter, MockRouterOptions, MockSignal, RenderComponentOptions, RenderResult, WaitForOptions } from './types'; /** * Mounts a custom element by tag name for testing and returns a handle * to interact with it. * * The element is created, configured with the given props and slots, * and appended to the container (defaults to `document.body`). Call * `unmount()` to remove the element and trigger its `disconnectedCallback`. * * @param tagName - The custom element tag name (must already be registered) * @param options - Props, slots, and container configuration * @returns A {@link RenderResult} with the element and an unmount function * @throws {Error} If the tag name is not a valid custom element name * * @example * ```ts * import { renderComponent } from '@bquery/bquery/testing'; * * const { el, unmount } = renderComponent('my-counter', { * props: { start: '5' }, * }); * expect(el.shadowRoot?.textContent).toContain('5'); * unmount(); * ``` */ export declare function renderComponent(tagName: string, options?: RenderComponentOptions): RenderResult; /** * Synchronously flushes any pending reactive effects. * * In bQuery's reactive system, effects outside of a batch are executed * synchronously. This helper exists primarily for clarity and for * flushing effects that may have been deferred inside a batch. * * Internally it performs a no-op batch to trigger the flush of any * pending observers that were queued during a prior `batch()` call. * * @example * ```ts * import { signal, batch } from '@bquery/bquery/reactive'; * import { flushEffects } from '@bquery/bquery/testing'; * * const count = signal(0); * let observed = 0; * effect(() => { observed = count.value; }); * * batch(() => { count.value = 42; }); * flushEffects(); * expect(observed).toBe(42); * ``` */ export declare function flushEffects(): void; /** * Creates a controllable signal for tests with `set()` and `reset()` helpers. * * This is a thin wrapper around `signal()` that records the initial value * and adds explicit `set()` / `reset()` methods for clearer test intent. * * @template T - The type of the signal value * @param initialValue - The initial value * @returns A {@link MockSignal} instance * * @example * ```ts * import { mockSignal } from '@bquery/bquery/testing'; * * const count = mockSignal(0); * count.set(5); * expect(count.value).toBe(5); * count.reset(); * expect(count.value).toBe(0); * ``` */ export declare function mockSignal(initialValue: T): MockSignal; /** * Creates a lightweight mock router for testing that does not interact * with the browser History API. * * The mock router provides a reactive `currentRoute` signal that updates * when `push()` or `replace()` is called, making it ideal for testing * components or logic that depend on route state. * * @param options - Mock router configuration * @returns A {@link MockRouter} instance * * @example * ```ts * import { mockRouter } from '@bquery/bquery/testing'; * * const router = mockRouter({ * routes: [ * { path: '/', component: () => null }, * { path: '/user/:id', component: () => null }, * ], * initialPath: '/', * }); * * router.push('/user/42'); * expect(router.currentRoute.value.params.id).toBe('42'); * router.destroy(); * ``` */ export declare function mockRouter(options?: MockRouterOptions): MockRouter; /** * Dispatches a synthetic event on an element and flushes pending effects. * * By default the event bubbles, is cancelable, and is composed (crosses * shadow DOM boundaries). Pass a `detail` option to create a `CustomEvent`. * * @param el - The target element * @param eventName - The event type (e.g. 'click', 'input', 'my-event') * @param options - Event configuration * @returns `true` if the event was not cancelled * * @example * ```ts * import { fireEvent } from '@bquery/bquery/testing'; * * const button = document.createElement('button'); * let clicked = false; * button.addEventListener('click', () => { clicked = true; }); * fireEvent(button, 'click'); * expect(clicked).toBe(true); * ``` */ export declare function fireEvent(el: Element, eventName: string, options?: FireEventOptions): boolean; /** * Waits for a predicate to return `true`, polling at a configurable interval. * * Useful for asserting conditions that depend on asynchronous operations, * timers, or deferred reactive updates. * * @param predicate - A function that returns `true` when the condition is met * @param options - Timeout and interval configuration * @returns A promise that resolves when the predicate returns `true` * @throws {Error} If the predicate does not return `true` within the timeout * * @example * ```ts * import { waitFor } from '@bquery/bquery/testing'; * * await waitFor(() => document.querySelector('.loaded') !== null, { * timeout: 2000, * }); * ``` */ export declare function waitFor(predicate: () => boolean | Promise, options?: WaitForOptions): Promise; //# sourceMappingURL=testing.d.ts.map