Skip to main content Link Search Menu Expand Document (external link)

NodeTesting overview

Testing of the Server implementation.

Added in v1.0.0


Table of contents


constructors

handler

Testing of Handler.Handler<A, E, R>.

Signature

export declare const handler: <A extends ApiEndpoint.ApiEndpoint.Any, E, R>(
  app: Handler.Handler<A, E, R>
) => Effect.Effect<
  HttpClient.HttpClient,
  never,
  | Scope.Scope
  | Exclude<
      Exclude<
        Exclude<R, HttpServerRequest.HttpServerRequest | Scope.Scope>,
        HttpServer.HttpServer | HttpPlatform.HttpPlatform | Etag.Generator | NodeContext.NodeContext
      >,
      NodeContext.NodeContext
    >
>

Example

import { HttpClientRequest } from "@effect/platform"
import { Schema } from "effect"
import { Effect } from "effect"
import { Api, Handler } from "effect-http"
import { NodeTesting } from "effect-http-node"

const myEndpoint = Api.get("myEndpoint", "/my-endpoint").pipe(
  Api.setResponseBody(Schema.Struct({ hello: Schema.String }))
)

const myHandler = Handler.make(myEndpoint, () => Effect.succeed({ hello: "world" }))

Effect.gen(function* () {
  const client = yield* NodeTesting.handler(myHandler)
  const response = yield* client.execute(HttpClientRequest.get("/my-endpoint"))

  assert.deepStrictEqual(response.status, 200)
  assert.deepStrictEqual(yield* response.json, { hello: "world" })
}).pipe(Effect.scoped, Effect.runFork)

Added in v1.0.0

make

Create a testing client for the Server.

Signature

export declare const make: <R, E, A extends Api.Api.Any>(
  app: HttpApp.Default<E, R>,
  api: A,
  options?: any
) => Effect.Effect<
  Client.Client<A>,
  never,
  | Scope.Scope
  | Exclude<
      Exclude<
        Exclude<
          Exclude<R, HttpServerRequest.HttpServerRequest | Scope.Scope>,
          HttpServer.HttpServer | HttpPlatform.HttpPlatform | Etag.Generator | NodeContext.NodeContext
        >,
        SwaggerRouter.SwaggerFiles
      >,
      NodeContext.NodeContext
    >
>

Added in v1.0.0

makeRaw

Create a testing client for the Server. Instead of the Client.Client interface it returns a raw @effect/platform/Http/Client Client with base url set.

Signature

export declare const makeRaw: <R, E>(
  app: HttpApp.Default<E, R>
) => Effect.Effect<
  HttpClient.HttpClient,
  never,
  | Scope.Scope
  | Exclude<
      Exclude<
        Exclude<
          Exclude<R, HttpServerRequest.HttpServerRequest | Scope.Scope>,
          HttpServer.HttpServer | HttpPlatform.HttpPlatform | Etag.Generator | NodeContext.NodeContext
        >,
        SwaggerRouter.SwaggerFiles
      >,
      NodeContext.NodeContext
    >
>

Added in v1.0.0