/** * vapor-chamber - Testing utilities * * createTestBus() creates a command bus that records all dispatched commands * without executing real handlers. Useful for unit-testing components that * use useCommand() without wiring up the full application logic. * * v0.4.3: Added snapshot assertions and time-travel through dispatch history. * v0.3.0: Added on(), request(), respond(), getUndoHandler() stubs. * * @example * const bus = createTestBus(); * setCommandBus(bus); * * // Dispatch something under test * bus.dispatch('cartAdd', cart, { id: 1 }); * * // Assert * expect(bus.wasDispatched('cartAdd')).toBe(true); * expect(bus.getDispatched('cartAdd')[0].cmd.payload).toEqual({ id: 1 }); * * // Snapshot: get a serializable copy of recorded dispatches * const snap = bus.snapshot(); * * // Time-travel: replay dispatches up to (and including) index N * const state = bus.travelTo(2); */ import type { Command, CommandResult, CommandBus, BusInspection } from './command-bus'; export interface RecordedDispatch { cmd: Command; result: CommandResult; } export interface TestBus extends CommandBus { /** All dispatched commands in order */ readonly recorded: RecordedDispatch[]; /** True if any command with this action was dispatched */ wasDispatched(action: string): boolean; /** All recorded dispatches for a given action */ getDispatched(action: string): RecordedDispatch[]; /** Clear the recorded list and listeners */ clear(): void; /** Read-only dispatch — skips beforeHooks, runs handler + plugins, fires afterHooks. */ query(action: string, target: any, payload?: any): CommandResult; /** Fire a domain event — notifies on() listeners, no handler required, no result. */ emit(event: string, data?: any): void; /** Returns all registered action names. */ registeredActions(): string[]; /** * Snapshot — returns a deep-cloned, serializable copy of the recorded list. * Safe to compare with `toEqual` in any test framework. */ snapshot(): RecordedDispatch[]; /** * travelTo — returns the ordered list of commands from dispatch index 0 * through `index` (inclusive). Useful for asserting the sequence of events * that led to a particular state. * * @param index 0-based index into recorded[]. Clamped to valid range. */ travelTo(index: number): Command[]; /** * travelToAction — returns all commands dispatched up to and including * the last occurrence of `action`. Useful for "what happened before this action". */ travelToAction(action: string): Command[]; /** Full topology snapshot — actions, plugins, hooks, listeners, seal state. */ inspect(): BusInspection; } /** * Creates a test bus that stubs all handlers (returning `{ ok: true }`) unless * you register your own via `bus.register()`. All dispatches are recorded. */ export declare function createTestBus(opts?: { passthroughHandlers?: boolean; }): TestBus; //# sourceMappingURL=testing.d.ts.map