Connectum API Reference / @connectum/testing / index / mockService
Function: mockService() ​
mockService<
S>(service,impl):MockService
Defined in: testing/src/mockResolver.ts:44
Type-safe constructor for a MockService. Pairs a service descriptor with handlers typed against it.
A handler that throws a ConnectError answers with exactly that error. Any other exception (a typo in the mock, a rejected promise, a thrown string) reaches the caller as a ConnectError with code Internal, the exception's own message and the exception itself as cause, so a broken mock shows up in the test output instead of as an anonymous "internal error".
Type Parameters ​
S ​
S extends DescService
Parameters ​
service ​
S
impl ​
Partial<ServiceImpl<S>>
Returns ​
Example ​
ts
mockService(InventoryService, {
getStock: () => create(StockSchema, { units: 7 }),
});