Askr
Guides

Testing HTTP Applications

Use testing http applications with the current published Askr packages.

  • @askrjs/testing0.0.1
  • @askrjs/server0.0.4

How to use testing http applications

Start from an explicit route registry and add one application boundary at a time so browser, server, and production behavior stay testable.

  1. Import the published @askrjs/testing and @askrjs/server entrypoint.
  2. Keep testing http applications configuration next to the component, route, or server composition root that owns it.
  3. Handle pending, unavailable, cancellation, and failure states, then verify the production path.
export const registry = createRouteRegistry(() => {
  group({ layout: AppLayout }, () => {
    route('/', DashboardPage);
    route('/projects/{projectId}', ProjectPage);
    route('/404', NotFoundPage);
  });
});

Goal and architecture

`@askrjs/testing` drives an Askr server through its Web `Request`/`Response` boundary without opening a port. It is Node-only, runner-neutral, and deliberately returns native `Response` objects so Vitest, Node test, or another assertion library can inspect the same contract production adapters receive.

Request injection

Use `inject(target, input, init?)` for one request, `createTestRequest()` when you need explicit query, JSON, form, header, or abort setup, and `createTestClient(target, options?)` for repeated method calls against one base URL. The target can be a fetch-compatible object or a request handler function; thrown errors and streaming bodies pass through unchanged.

Cookie handling is opt-in. Pass `cookies: true` for a client-private standards-backed jar, or share a jar created by `createTestCookieJar()` across clients. Redirects are manual by default; use `redirect: "follow"` to exercise cookie capture, relative locations, method rewriting, and cross-origin credential stripping without allowing the test to reach the network.

Verification

Assert the native response status, headers, and body, then cover abort propagation, redirect policy, and cookie scope when the endpoint uses them. Keep transport-adapter tests separate: request injection proves the application contract, while a smaller adapter suite proves Node or another host translates real network requests correctly.