Setu-TS
    Preparing search index...

    Function inject

    • 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.

      Parameters

      Returns Promise<InjectResponse>

      The inject response

      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);

      0.1.0