@askrjs/testing
Exports from the declarations published in @askrjs/testing. Signatures reflect the published artifact.
Exports
This entrypoint publishes 18 exports. Use the anchored symbol rows for direct links. Type-only exports are labeled separately from runtime values.
BodyRequestOptionstype
BodyRequestOptions: RequestOptionsBase & {
method: "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS" | "post" | "put" | "patch" | "delete" | "options";
} & BodyModeOptions for a request that may carry a body, restricted to methods that support one.
createTestClienttype
createTestClient: (target: Injectable, options?: TestClientOptions) => TestClientCreate a {@link TestClient} bound to a target for repeated request injection. The returned client applies shared defaults (base URL, headers, cookie jar, redirect behavior) to every request made through it, and follows redirects automatically unless `redirect` is overridden.
const client = createTestClient(app, { baseUrl: "https://example.com", cookies: true });
const response = await client.get("/users");createTestCookieJartype
createTestCookieJar: () => TestCookieJarCreate an in-memory {@link TestCookieJar} backed by `tough-cookie`, suitable for use as the `cookies` option of a {@link TestClient}.
createTestRequesttype
createTestRequest: (input: string | URL, options?: InjectOptions) => RequestBuild a `Request` for testing from a path or URL and a set of options. Resolves `input` against `options.baseUrl` (defaulting to `https://askr.test/`), appends any `query` parameters, and serializes at most one of `body`, `json`, or `form` into the request body, setting an appropriate `content-type` header when one isn't already present. Throws a `TypeError` if more than one body mode is supplied, if `json` is `undefined`, or if a `GET`/`HEAD` request is given a body.
Formtype
Form: URLSearchParams | Iterable<readonly [string, FormValue]> | Record<string, FormValue | readonly FormValue[] | undefined>URL-encoded form body data, accepted as `URLSearchParams`, an iterable of entries, or a plain record.
FormValuetype
FormValue: string | number | booleanA single form field value, coerced to `string` when serialized.
GetHeadOptionstype
GetHeadOptions: RequestOptionsBase & {
method?: "GET" | "HEAD" | "get" | "head";
} & NoBodyOptions for a body-less `GET` or `HEAD` request.
injecttype
inject: { (target: Injectable, request: Request, options?: Pick<InjectOptions, "maxRedirects">): Promise<Response>; (target: Injectable, input: string | URL, options?: InjectOptions): Promise<Response>; }Inject a single request into a target and return the resulting response, following redirects up to `maxRedirects` hops. Inject a request built from a path/URL and options into a target and return the resulting response, following redirects up to `maxRedirects` hops.
const response = await inject(app, "/users", { method: "GET" });Injectabletype
Injectable: RequestTarget | RequestHandlerAnything that can receive an injected test request: a {@link RequestTarget} or a {@link RequestHandler}.
InjectOptionstype
InjectOptions: GetHeadOptions | BodyRequestOptionsOptions accepted when injecting a request, covering both body-less and body-carrying methods.
Querytype
Query: URLSearchParams | Iterable<readonly [string, QueryValue]> | Record<string, QueryValue | readonly QueryValue[] | undefined>Query string parameters, accepted as `URLSearchParams`, an iterable of entries, or a plain record.
QueryValuetype
QueryValue: string | number | booleanA single query string value, coerced to `string` when serialized.
RequestHandlertype
RequestHandler: (request: Request) => Response | Promise<Response>A function that handles a `Request` and produces a `Response`, synchronously or asynchronously.
RequestTargettype
RequestTarget: anyA target that can receive an injected request directly via a `fetch`-style method.
fetch- fetch(request: Request): Response | Promise<Response>;
TestClienttype
TestClient: anyA reusable HTTP client that injects requests into a target and follows redirects.
cookies- readonly cookies?: TestCookieJar;
request- request(path: string | URL, options?: InjectOptions): Promise<Response>;
get- get(path: string | URL, options?: Omit<GetHeadOptions, "method">): Promise<Response>;
head- head(path: string | URL, options?: Omit<GetHeadOptions, "method">): Promise<Response>;
post- post(path: string | URL, options?: Omit<BodyRequestOptions, "method">): Promise<Response>;
put- put(path: string | URL, options?: Omit<BodyRequestOptions, "method">): Promise<Response>;
patch- patch(path: string | URL, options?: Omit<BodyRequestOptions, "method">): Promise<Response>;
delete- delete(path: string | URL, options?: Omit<BodyRequestOptions, "method">): Promise<Response>;
options- options(path: string | URL, options?: Omit<BodyRequestOptions, "method">): Promise<Response>;
TestClientOptionstype
TestClientOptions: anyOptions for constructing a {@link TestClient}.
baseUrl- baseUrl?: string | URL;
headers- headers?: HeadersInit;
cookies- Enable an automatically managed cookie jar (`true`), or supply an existing {@link TestCookieJar}.
redirect- redirect?: RequestRedirect;
maxRedirects- maxRedirects?: number;
TestCookietype
TestCookie: anyA cookie as read back from a {@link TestCookieJar}.
name- name: string;
value- value: string;
domain- domain?: string;
path- path?: string;
expires- expires?: Date | "Infinity";
httpOnly- httpOnly: boolean;
secure- secure: boolean;
sameSite- sameSite?: "strict" | "lax" | "none";
TestCookieJartype
TestCookieJar: anyA cookie jar used to persist and replay cookies across injected requests.
setCookie- setCookie(cookie: string, url: string | URL): Promise<void>;
getCookies- getCookies(url: string | URL): Promise<TestCookie[]>;
clear- clear(): Promise<void>;