Askr documentation
Generated API snapshot

@askrjs/askr/testing

Exports from the declarations published in @askrjs/askr. Signatures reflect the published artifact.

Exports

This entrypoint publishes 29 exports. Use the anchored symbol rows for direct links. Type-only exports are labeled separately from runtime values.

cleanuptype

cleanup: (target: RenderResult | HTMLElement) => void

Tear down a test render, given either its {@link RenderResult} or container element.

clicktype

click: (element: Element) => boolean

Dispatch the browser click sequence expected by Askr's delegated events.

createInvalidationRecordertype

createInvalidationRecorder: () => InvalidationRecorder

Start recording {@link invalidate } calls for assertions; call `stop()` when done.

createMutationTestRegistrytype

createMutationTestRegistry: () => MutationTestRegistry

Create a keyed mutation fixture registry for a test render runtime.

createQueryTestRegistrytype

createQueryTestRegistry: () => QueryTestRegistry

Create a keyed query fixture registry for a test render runtime.

dispatchtype

dispatch: (target: EventTarget, event: Event | string, init?: DispatchEventInit) => boolean

Dispatch an event (constructed from a type string, or given directly) on `target`.

flushtype

flush: () => void

Synchronously flush the runtime's scheduled work (renders, effects).

getRouteWarningstype

getRouteWarnings: (options: MatchRouteOptions) => RoutePatternWarning[]

Find named-splat routes whose reserved segments collide with sibling static routes.

InvalidationRecordtype

InvalidationRecord: any

A single recorded call to {@link invalidate }, captured by {@link createInvalidationRecorder}.

prefix
prefix: string;
markPendingWrite
markPendingWrite: boolean;

InvalidationRecordertype

InvalidationRecorder: any

Recorder returned by {@link createInvalidationRecorder}.

calls
readonly calls: readonly InvalidationRecord[];
prefixes
readonly prefixes: readonly string[];
clear
clear(): void;
stop
stop(): void;

matchRoutetype

matchRoute: (path: string, options: MatchRouteOptions) => RouteMatch | null

Match `path` against a route registry for tests, without mounting the app.

mockQuerytype

mockQuery: (<T extends {}>(data: T, options?: MockQueryOptions) => Query<T>) & { loading<T extends {} = {}>(options?: MockQueryOptions): Query<T>; error<T extends {} = {}>(error: {}, previousData?: T, options?: MockQueryOptions): Query<T>; refreshing<T extends {}>(data: T, options?: MockQueryOptions): Query<T>; stale<T extends {}>(data: T, reason?: StaleValueReason, options?: MockQueryOptions): Query<T>; pendingWrite<T extends {}>(data: T, options?: MockQueryOptions): Query<T>; }

Build a fresh {@link Query} fixture for tests: call directly with data, or use `.loading()`/`.error()`/`.refreshing()`/`.stale()`/`.pendingWrite()`.

MockQueryOptionstype

MockQueryOptions: any

Options for {@link mockQuery} fixtures.

refresh
refresh?: MockRefresh;

MockRefreshtype

MockRefresh: () => void | Promise<void>

Refresh callback for a {@link mockQuery} fixture, invoked by the query's `refresh()`.

mounttype

mount: (component: ComponentFunction, options?: RenderOptions) => RenderResult

Alias for {@link render}.

MutationFixturetype

MutationFixture: Mutation<TInput, TResult> & {
  /** Inputs received by the fixture's execute method. */
  readonly inputs: readonly TInput[];
  /** Move the fixture to pending without starting application work. */
  setPending(): void;
  /** Resolve the current fixture execution and expose its result. */
  succeed(result: TResult): void;
  /** Reject the current fixture execution and expose its error. */
  fail(error: {}): void;
}

A {@link Mutation} whose state is driven manually via `setPending`/`succeed`/`fail`.

MutationFixtureInitialtype

MutationFixtureInitial: {
  pending?: boolean;
  error?: {} | null;
  result?: TResult;
}

Initial state for {@link mutationState}; exactly one of `pending`/`error`/`result` may be set.

mutationStatetype

mutationState: (<TInput = unknown, TResult = unknown>(initial?: MutationFixtureInitial<TResult>) => MutationFixture<TInput, TResult>) & { idle<TInput = unknown, TResult = unknown>(): MutationFixture<TInput, TResult>; pending<TInput = unknown, TResult = unknown>(): MutationFixture<TInput, TResult>; success<TInput = unknown, TResult = unknown>(result: TResult): MutationFixture<TInput, TResult>; error<TInput = unknown, TResult = unknown>(error: {}): MutationFixture<TInput, TResult>; }

Build a {@link MutationFixture} for tests: call directly with initial state, or use `.idle()`/`.pending()`/`.success(result)`/`.error(error)`.

MutationTestRegistrytype

MutationTestRegistry: any

Keyed mutation fixture registry returned by {@link createMutationTestRegistry}.

runtime
readonly runtime: DataRuntime;
set
set<TInput, TResult>(key: string, mutation: Mutation<TInput, TResult>): void;
delete
delete(key: string): void;
clear
clear(): void;

queryStatetype

queryState: { fresh: typeof createFreshQuery; loading: <T extends {} = {}>(options?: MockQueryOptions) => Query<T>; error: <T extends {} = {}>(error: {}, previousData?: T, options?: MockQueryOptions) => Query<T>; refreshing: <T extends {}>(data: T, options?: MockQueryOptions) => Query<T>; stale: <T extends {}>(data: T, reason?: StaleValueReason, options?: MockQueryOptions) => Query<T>; pendingWrite: <T extends {}>(data: T, options?: MockQueryOptions) => Query<T>; }

Alias table mirroring {@link mockQuery}'s state builders (`fresh`, `loading`, `error`, ...).

QueryTestRegistrytype

QueryTestRegistry: any

Keyed query fixture registry returned by {@link createQueryTestRegistry}.

runtime
readonly runtime: DataRuntime;
set
set<T extends {}>(key: string, query: Query<T>): void;
delete
delete(key: string): void;
clear
clear(): void;

rendertype

render: (component: ComponentFunction, options?: RenderOptions) => RenderResult

Mount `component` as an island into a test container and flush pending work.

RenderOptionstype

RenderOptions: any

Options for {@link render} and {@link mount}.

container
Existing element to own for the duration of the render. When omitted, the harness appends a managed `<div>` to `document.body`.
cleanupStrict
Surface lifecycle cleanup errors during unmount.

RenderResulttype

RenderResult: any

Handle to a mounted test render, returned by {@link render}/{@link mount}/{@link renderRoute}.

container
readonly container: HTMLElement;
root
readonly root: HTMLElement;
flush
flush(): void;
dispatch
dispatch(target: EventTarget, event: Event | string, init?: DispatchEventInit): boolean;
unmount
unmount(): void;
cleanup
cleanup(): void;

renderRoutetype

renderRoute: (options: RouteRenderOptions) => Promise<RenderResult>

Mount a routed app (via {@link createSPA }) into a test container for the given route registry.

RoutePatternWarningtype

RoutePatternWarning: any

A splat-route/static-route path collision reported by {@link getRouteWarnings}.

kind
kind: 'route-collision';
path
path: string;
conflictingPath
conflictingPath: string;
segment
segment: string;
namespace
namespace: string | undefined;
message
message: string;

RouteRenderOptionstype

RouteRenderOptions: any

Options for {@link renderRoute}.

registry
registry: RouteRegistry;
url
Initial path, query, and hash for the routed render.
auth
auth?: RouteAuthOptions;
dataRuntime
dataRuntime?: DataRuntime;

submittype

submit: (form: HTMLFormElement) => boolean

Dispatch a cancelable bubbling submit event on a form.

typetype

type: (element: HTMLInputElement | HTMLTextAreaElement, text: string) => void

Set a text control's value and emit an input event for each character.