inject(app: IKernelApplication,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.
Example 1
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);
app: IKernelApplication
A started kernel application
request: string | InjectRequest | Request
String URL, InjectRequest object, or web Request
Promise<InjectResponse>
The inject response