@askrjs/testing
Exports from the declarations published in @askrjs/testing. Signatures reflect the published artifact.
Exports
This entrypoint publishes 11 exports. Use the anchored symbol rows for direct links. Type-only exports are labeled separately from runtime values.
createTestClient
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. Redirects are manual
unless redirect: "follow" is supplied.
const client = createTestClient(app, { baseUrl: "https://example.com", cookies: true });
const response = await client.get("/users");createTestCookieJar
createTestCookieJar: () => TestCookieJarCreate an in-memory {@link TestCookieJar} backed by tough-cookie, suitable
for use as the cookies option of a {@link TestClient}.
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.
inject
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.
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- Non-negative safe integer; defaults to 10.
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>;