Overriding a Single Method in `Path` for Testing Without Type Casting

I wanna override a single method of
Path
in tests, is there easier way to achieve it without type casting?

I tried to do it via Effect.provideService but it requires full implementation of
Path
so had to type cast. Also tried Layer.mock but found it only works for effects where
Path
is not effectful.

describe('program', () => {
  it('calls path.join', async () => {
    const join = mock();
    const layer = createTestPathLayer({ join });
    await program.pipe(Effect.provide(layer), Effect.runPromise);

    expect(join).toHaveBeenCalled();
  });
});

const createTestPathLayer = (overrides?: Partial<Path.Path>) =>
  Layer.effect(
    Path.Path,
    Effect.gen(function* () {
      const path = yield* Path.Path;

      return { ...path, ...overrides };
    }).pipe(Effect.provide(Path.layer)),
  );
Was this page helpful?