rest-vir - v2.2.0
    Preparing search index...

    Function testApi

    • Test your api with actual Request and Response objects! The returned object includes utilities for sending fetch requests and WebSocket connections to the api.

      Make sure to use the kill method on the output after your tests are finished. To automatically kill the server, use describeApi instead.

      By default, this uses Fastify's request injection strategy to avoid using up real system ports. To instead use an actual port, set port in the options parameter.

      Type Parameters

      Parameters

      • api: Readonly<Api>
      • testApiOptions: Readonly<
            Omit<
                PartialWithUndefined<RunApiUserOptions>,
                "workerCount" | "preventWorkerRespawn",
            >,
        > = {}

      Returns Promise<
          {
              connectWebSocket: ConnectTestWebSocket<Api>;
              fetchEndpoint: FetchTestEndpoint<Api>;
              server: Readonly<FastifyInstance>;
              kill(this: void): Promise<void>;
          },
      >

      import {testApi} from '@rest-vir/host';

      const {connectWebSocket, kill, fetchEndpoint} = await testApi(myApiImplementation);

      // run tests

      await kill();