const mockInvoiceRepository = {
getInvoiceById: vi.fn(),
};
const TestLayer = Layer.mergeAll(
// Argument of type { getInvoiceById } is not assignable to parameter of type
// is missing the following properties from type {func1, func2, func3 names}
Layer.succeed(InvoiceRepositoryService, InvoiceRepositoryService.of({
getInvoiceById: mockInvoiceRepository.getInvoiceById,
})),
);
// The test
it.effect("...", () => Effect.gen(function()* {
const repo = yield* InvoiceRepositoryService;
// ...test logic
}).pipe(
Effect.provide(TestLayer)
);
// My service
export class InvoiceRepositoryService extends Effect.Service<InvoiceRepositoryService>()("InvoiceRepository", {
effect: Effect.gen(function* () {
return {
getInvoiceById: (id: string) => Effect.gen(function()* {
// ...
}),
// ...func1, ...func2, ...func3
}
}),
dependencies: [],
})
const mockInvoiceRepository = {
getInvoiceById: vi.fn(),
};
const TestLayer = Layer.mergeAll(
// Argument of type { getInvoiceById } is not assignable to parameter of type
// is missing the following properties from type {func1, func2, func3 names}
Layer.succeed(InvoiceRepositoryService, InvoiceRepositoryService.of({
getInvoiceById: mockInvoiceRepository.getInvoiceById,
})),
);
// The test
it.effect("...", () => Effect.gen(function()* {
const repo = yield* InvoiceRepositoryService;
// ...test logic
}).pipe(
Effect.provide(TestLayer)
);
// My service
export class InvoiceRepositoryService extends Effect.Service<InvoiceRepositoryService>()("InvoiceRepository", {
effect: Effect.gen(function* () {
return {
getInvoiceById: (id: string) => Effect.gen(function()* {
// ...
}),
// ...func1, ...func2, ...func3
}
}),
dependencies: [],
})