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

index overview

Added in v1.0.0


Table of contents


exports

From “vitest”

Re-exports all named exports from the “vitest” module.

Signature

export * from "vitest"

Added in v1.0.0

utils

API (type alias)

Signature

export type API = V.TestAPI<{}>

Added in v1.0.0

Vitest (namespace)

Added in v1.0.0

Methods (interface)

Signature

export interface Methods<R = never> extends MethodsNonLive<R> {
  readonly live: Vitest.Tester<R>
  readonly scopedLive: Vitest.Tester<Scope.Scope | R>
}

Added in v1.0.0

MethodsNonLive (interface)

Signature

export interface MethodsNonLive<R = never> extends API {
  readonly effect: Vitest.Tester<TestServices.TestServices | R>
  readonly flakyTest: <A, E, R2>(
    self: Effect.Effect<A, E, R2>,
    timeout?: Duration.DurationInput
  ) => Effect.Effect<A, never, R2>
  readonly scoped: Vitest.Tester<TestServices.TestServices | Scope.Scope | R>
  readonly layer: <R2, E>(
    layer: Layer.Layer<R2, E, R>,
    options?: {
      readonly timeout?: Duration.DurationInput
    }
  ) => {
    (f: (it: Vitest.MethodsNonLive<R | R2>) => void): void
    (name: string, f: (it: Vitest.MethodsNonLive<R | R2>) => void): void
  }

  /**
   * @since 1.0.0
   */
  readonly prop: <const Arbs extends Arbitraries>(
    name: string,
    arbitraries: Arbs,
    self: (
      properties: { [K in keyof Arbs]: Arbs[K] extends FC.Arbitrary<infer T> ? T : Schema.Schema.Type<Arbs[K]> },
      ctx: V.TaskContext<V.RunnerTestCase<{}>> & V.TestContext
    ) => void,
    timeout?:
      | number
      | (V.TestOptions & {
          fastCheck?: FC.Parameters<{
            [K in keyof Arbs]: Arbs[K] extends FC.Arbitrary<infer T> ? T : Schema.Schema.Type<Arbs[K]>
          }>
        })
  ) => void
}

Added in v1.0.0

Test (interface)

Signature

export interface Test<R> {
  <A, E>(
    name: string,
    self: TestFunction<A, E, R, [V.TaskContext<V.RunnerTestCase<{}>> & V.TestContext]>,
    timeout?: number | V.TestOptions
  ): void
}

Added in v1.0.0

TestFunction (interface)

Signature

export interface TestFunction<A, E, R, TestArgs extends Array<any>> {
  (...args: TestArgs): Effect.Effect<A, E, R>
}

Added in v1.0.0

Tester (interface)

Signature

export interface Tester<R> extends Vitest.Test<R> {
  skip: Vitest.Test<R>
  skipIf: (condition: unknown) => Vitest.Test<R>
  runIf: (condition: unknown) => Vitest.Test<R>
  only: Vitest.Test<R>
  each: <T>(
    cases: ReadonlyArray<T>
  ) => <A, E>(name: string, self: TestFunction<A, E, R, Array<T>>, timeout?: number | V.TestOptions) => void
  fails: Vitest.Test<R>

  /**
   * @since 1.0.0
   */
  prop: <const Arbs extends Arbitraries, A, E>(
    name: string,
    arbitraries: Arbs,
    self: TestFunction<
      A,
      E,
      R,
      [
        { [K in keyof Arbs]: Arbs[K] extends FC.Arbitrary<infer T> ? T : Schema.Schema.Type<Arbs[K]> },
        V.TaskContext<V.RunnerTestCase<{}>> & V.TestContext
      ]
    >,
    timeout?:
      | number
      | (V.TestOptions & {
          fastCheck?: FC.Parameters<{
            [K in keyof Arbs]: Arbs[K] extends FC.Arbitrary<infer T> ? T : Schema.Schema.Type<Arbs[K]>
          }>
        })
  ) => void
}

Added in v1.0.0

Arbitraries (type alias)

Signature

export type Arbitraries =
  | Array<Schema.Schema.Any | FC.Arbitrary<any>>
  | { [K in string]: Schema.Schema.Any | FC.Arbitrary<any> }

Added in v1.0.0

addEqualityTesters

Signature

export declare const addEqualityTesters: () => void

Added in v1.0.0

describeWrapped

Signature

export declare const describeWrapped: (name: string, f: (it: Vitest.Methods) => void) => V.SuiteCollector

Added in v1.0.0

effect

Signature

export declare const effect: Vitest.Tester<TestServices.TestServices>

Added in v1.0.0

flakyTest

Signature

export declare const flakyTest: <A, E, R>(self: Effect.Effect<A, E, R>, timeout?: any) => Effect.Effect<A, never, R>

Added in v1.0.0

it

Signature

export declare const it: Vitest.Methods<never>

Added in v1.0.0

layer

Share a Layer between multiple tests, optionally wrapping the tests in a describe block if a name is provided.

Signature

export declare const layer: <R, E>(
  layer_: Layer.Layer<R, E>,
  options?: { readonly memoMap?: Layer.MemoMap; readonly timeout?: Duration.DurationInput }
) => {
  (f: (it: Vitest.MethodsNonLive<R>) => void): void
  (name: string, f: (it: Vitest.MethodsNonLive<R>) => void): void
}

Added in v1.0.0

import { expect, layer } from "@effect/vitest"
import { Context, Effect, Layer } from "effect"

class Foo extends Context.Tag("Foo")<Foo, "foo">() {
  static Live = Layer.succeed(Foo, "foo")
}

class Bar extends Context.Tag("Bar")<Bar, "bar">() {
  static Live = Layer.effect(
    Bar,
    Effect.map(Foo, () => "bar" as const)
  )
}

layer(Foo.Live)("layer", (it) => {
  it.effect("adds context", () =>
    Effect.gen(function* () {
      const foo = yield* Foo
      expect(foo).toEqual("foo")
    })
  )

  it.layer(Bar.Live)("nested", (it) => {
    it.effect("adds context", () =>
      Effect.gen(function* () {
        const foo = yield* Foo
        const bar = yield* Bar
        expect(foo).toEqual("foo")
        expect(bar).toEqual("bar")
      })
    )
  })
})

live

Signature

export declare const live: Vitest.Tester<never>

Added in v1.0.0

makeMethods

Signature

export declare const makeMethods: (it: V.TestAPI) => Vitest.Methods

Added in v1.0.0

prop

Signature

export declare const prop: <const Arbs extends Vitest.Arbitraries>(
  name: string,
  arbitraries: Arbs,
  self: (
    properties: { [K in keyof Arbs]: Arbs[K] extends FC.Arbitrary<infer T> ? T : Schema.Schema.Type<Arbs[K]> },
    ctx: V.TaskContext<V.RunnerTestCase<{}>> & V.TestContext
  ) => void,
  timeout?:
    | number
    | (V.TestOptions & {
        fastCheck?: FC.Parameters<{
          [K in keyof Arbs]: Arbs[K] extends FC.Arbitrary<infer T> ? T : Schema.Schema.Type<Arbs[K]>
        }>
      })
) => void

Added in v1.0.0

scoped

Signature

export declare const scoped: Vitest.Tester<any>

Added in v1.0.0

scopedLive

Signature

export declare const scopedLive: Vitest.Tester<Scope.Scope>

Added in v1.0.0