Package: @effect/vitest
Module: index
Share a Layer between multiple tests, optionally wrapping
the tests in a describe block if a name is provided.
Signature
declare const layer: <R, E>(layer_: Layer.Layer<R, E>, options?: { readonly memoMap?: Layer.MemoMap; readonly timeout?: Duration.Input; readonly excludeTestServices?: boolean; }) => { (f: (it: Vitest.MethodsNonLive<R>) => void): void; (name: string, f: (it: Vitest.MethodsNonLive<R>) => void): void; }
Since v4.0.0
import { expect, layer } from "@effect/vitest"
import { Effect, Layer, Context } from "effect"
class Foo extends Context.Service("Foo")<Foo, "foo">() {
static Live = Layer.succeed(Foo, "foo")
}
class Bar extends Context.Service("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")
}))
})
})