Skip to content

Function: mockService()

ts
function mockService<T>(
   service: Newable<T>, 
   container?: Container, 
   options?: MockServiceOptions): T;

Defined in: src/wirestate-core/test-utils/mock-service.ts:41

Mocks a service by binding it to an IoC container and returning its resolved instance.

Type Parameters

Type ParameterDescription
T extends objectThe type of the service being mocked.

Parameters

ParameterTypeDescription
serviceNewable<T>The service class constructor to mock.
containerContainerThe Inversify container to use (defaults to a new mock container).
optionsMockServiceOptionsAdditional options for mocking.

Returns

T

The resolved service instance.

Remarks

This is a high-level utility that combines mockContainer and mockBindService. If no container is provided, a fresh one is created.

Example

typescript
const service: MyService = mockService(MyService);