MCPcopy
hub / github.com/Effect-TS/effect / testLayer

Function testLayer

packages/platform/test/KeyValueStore.test.ts:6–86  ·  view source on GitHub ↗
(layer: Layer.Layer<KeyValueStore.KeyValueStore, E>)

Source from the content-addressed store, hash-verified

4import { Effect, identity, Layer, pipe, Schema } from "effect"
5
6export const testLayer = <E>(layer: Layer.Layer<KeyValueStore.KeyValueStore, E>) => {
7 const run = <E, A>(effect: Effect.Effect<A, E, KeyValueStore.KeyValueStore>) =>
8 Effect.runPromise(Effect.provide(effect, layer))
9
10 afterEach(() =>
11 run(Effect.gen(function*() {
12 const kv = yield* (KeyValueStore.KeyValueStore)
13 yield* (kv.clear)
14 }))
15 )
16
17 it("set", () =>
18 run(Effect.gen(function*() {
19 const kv = yield* (KeyValueStore.KeyValueStore)
20 yield* (kv.set("/foo/bar", "bar"))
21
22 const value = yield* (kv.get("/foo/bar"))
23 const length = yield* (kv.size)
24
25 assertSome(value, "bar")
26 strictEqual(length, 1)
27 })))
28
29 it("get/ missing", () =>
30 run(Effect.gen(function*() {
31 const kv = yield* (KeyValueStore.KeyValueStore)
32 yield* (kv.clear)
33 const value = yield* (kv.get("foo"))
34
35 assertNone(value)
36 })))
37
38 it("remove", () =>
39 run(Effect.gen(function*() {
40 const kv = yield* (KeyValueStore.KeyValueStore)
41 yield* (kv.set("foo", "bar"))
42 yield* (kv.remove("foo"))
43
44 const value = yield* (kv.get("foo"))
45 const length = yield* (kv.size)
46
47 assertNone(value)
48 strictEqual(length, 0)
49 })))
50
51 it("clear", () =>
52 run(Effect.gen(function*() {
53 const kv = yield* (KeyValueStore.KeyValueStore)
54 yield* (kv.set("foo", "bar"))
55 yield* (kv.clear)
56
57 const value = yield* (kv.get("foo"))
58 const length = yield* (kv.size)
59
60 assertNone(value)
61 strictEqual(length, 0)
62 })))
63

Callers 3

Calls 9

assertSomeFunction · 0.90
strictEqualFunction · 0.90
assertNoneFunction · 0.90
itFunction · 0.85
runFunction · 0.70
setMethod · 0.65
getMethod · 0.65
removeMethod · 0.65
modifyMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…