function inject
Since 0.1.0
inject(
request: string | InjectRequest | Request
): Promise<InjectResponse>

Free-function HTTP request injector with string, InjectRequest, and web-standard Request shorthand.

A string is a URL-only shorthand ({ method: 'GET', url: request }). For non-GET methods, use the InjectRequest object form directly. A web-standard Request is normalized field-by-field and delegated to app.inject() after reading its body. That read consumes the request, so a Request cannot be injected twice, nor injected and then passed to app.fetch() — the second call throws rather than silently sending no body. Build a separate Request per call.

Examples

Example 1

import { inject } from '@setu-ts/testing';

// String shorthand (GET only)
const res = await inject(app, '/users');

// InjectRequest object
const res2 = await inject(app, {
  method: 'POST',
  url: '/users',
  body: { name: 'test' },
});

// Web Request
const req = new Request('http://localhost/users', {
  method: 'POST',
  body: JSON.stringify({ name: 'test' }),
});
const res3 = await inject(app, req);

Parameters

A started kernel application

request: string | InjectRequest | Request

String URL, InjectRequest object, or web Request

Return Type

Promise<InjectResponse>

The inject response

Usage

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