# @askrjs/askr/testing

> Published API exports for @askrjs/askr/testing.

Source: [https://askrjs.com/docs/reference/api/askr/testing](https://askrjs.com/docs/reference/api/askr/testing)

Status: stable. Packages: @askrjs/askr/testing.

**Published packages are authoritative.** Examples may lag behind a published contract. When guidance differs, verify the exports and TypeScript declarations in your installed package, then file an issue.

## Exports

This entrypoint publishes 29 exports from the declarations shipped by @askrjs/askr.

### `cleanup`

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

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

### `click`

```ts
click: (element: Element) => boolean
```

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

### `createInvalidationRecorder`

```ts
createInvalidationRecorder: () => InvalidationRecorder
```

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

### `createMutationTestRegistry`

```ts
createMutationTestRegistry: () => MutationTestRegistry
```

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

### `createQueryTestRegistry`

```ts
createQueryTestRegistry: () => QueryTestRegistry
```

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

### `dispatch`

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

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

### `flush`

```ts
flush: () => void
```

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

### `getRouteWarnings`

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

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

### `InvalidationRecord`

```ts
InvalidationRecord: any
```

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

- `prefix`: prefix: string;

- `markPendingWrite`: markPendingWrite: boolean;

### `InvalidationRecorder`

```ts
InvalidationRecorder: any
```

Recorder returned by {@link createInvalidationRecorder}.

- `calls`: readonly calls: readonly InvalidationRecord[];

- `prefixes`: readonly prefixes: readonly string[];

- `clear`: clear(): void;

- `stop`: stop(): void;

### `matchRoute`

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

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

### `mockQuery`

```ts
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()`.

### `MockQueryOptions`

```ts
MockQueryOptions: any
```

Options for {@link mockQuery} fixtures.

- `refresh`: refresh?: MockRefresh;

### `MockRefresh`

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

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

### `mount`

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

Alias for {@link render}.

### `MutationFixture`

```ts
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`.

### `MutationFixtureInitial`

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

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

### `mutationState`

```ts
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)`.

### `MutationTestRegistry`

```ts
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;

### `queryState`

```ts
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`, ...).

### `QueryTestRegistry`

```ts
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;

### `render`

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

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

### `RenderOptions`

```ts
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.

### `RenderResult`

```ts
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;

### `renderRoute`

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

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

### `RoutePatternWarning`

```ts
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;

### `RouteRenderOptions`

```ts
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;

### `submit`

```ts
submit: (form: HTMLFormElement) => boolean
```

Dispatch a cancelable bubbling submit event on a form.

### `type`

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

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

## Documentation navigation

[Previous](https://askrjs.com/docs/reference/api/askr/data/index.md) | [Next](https://askrjs.com/docs/reference/api/askr/fx/index.md)
