Effect CommunityEC
Effect Community2y ago
29 replies
addamsson

Testing Services with Effect

How can I "extract" a specific service from a Layer or a
Runtime
? I'm trying to test my code and I have a test runtime with test implementations for all my services but I'd like to set up their internal state before I run my test like:
// runtime setup
const TEST_SERVICES = Layer.mergeAll(
    MyService.test
);

export const TEST_RUNTIME = ManagedRuntime.make(TEST_DEPS);

// in my test
const myService = MY_RUNTIME.extract(MyService)

// prepare
myService.doSomething(...);

// test
myProgramUsingMyService();

expect(myService.getSomething()).toBe(...)

or is this some better way to test my services using Effect?
Was this page helpful?