class MockResponse
implements IResponse
Since 0.1.0

In-memory IResponse double with snapshot() and ended getter.

Implements the full IResponse surface so that middleware tests can inspect snapshot() (status, headers, body) and assert short-circuit behavior via the ended getter. Chaining methods (status, header, appendHeader) return this; terminal methods set #ended = true and return a HandlerResult brand.

Properties

readonly
ended: boolean

Methods

appendHeader(
name: string,
value: string
): IResponse

Appends a response header, preserving any existing values for the same name rather than replacing them (unlike IResponse.header, which overwrites). This is the correct way to emit multiple headers of the same name — most notably several Set-Cookie headers (e.g. an access cookie plus a refresh cookie, or deleting several cookies at once).

header(
name: string,
value: string
): IResponse

Sets a response header.

html(_body: string): HandlerResult

Terminal HTML response — mirrors the kernel builder's html(), so a test asserting on the double cannot pass where the real builder would fail.

json<T>(_body: T): HandlerResult

Sends a JSON response.

redirect(
url: string,
_status?: number
): HandlerResult

Sends a redirect response.

send(_body?: Uint8Array): HandlerResult

Sends a raw byte response.

Since 0.1.0
snapshot(): ResponseSnapshot

Returns a snapshot of the current response state (status, headers, body). Enables middleware to inspect the response after next() returns — required for transparent response caching.

The returned object is a READ view, not a defensive copy: headers is the live Headers instance backing the response. Treat it as read-only — mutating it mutates the response. (No copy is taken deliberately: cloning a Headers collapses repeated Set-Cookie values into one comma-joined header, which would corrupt multi-cookie responses.)

Returns a discriminated union keyed on streaming: when false, body is Uint8Array | string | null (buffered); when true, body is a ReadableStream<Uint8Array> (live stream). Middleware that reads the body (e.g. cache middleware) must check streaming first to avoid draining a live stream.

status(code: number): IResponse

Sets the response status code.

Since 0.2.0
stream(body: ReadableStream<Uint8Array>): HandlerResult

Sends a streaming response body.

Accepts a web-standard ReadableStream so that a handler can flush bytes progressively over a long-lived connection instead of buffering a whole body before send. This is the shared foundation for Server-Sent Events (Milestone 43), React SSR streaming (Milestone 44), large file downloads (storage-plugin, Milestone 28), and export / report responses.

Because the runtime maps the response to a web-standard new Response(streamBody, { status, headers }), streaming is free on every platform (Node via Hono, Deno, Bun, Cloudflare Workers) with no buffer-then-send.

text(_body: string): HandlerResult

Sends a plain-text response.

Usage

import { MockResponse } from "testing/src/index.ts";