Skip to content

MockContainer

type MockContainer = Container

Minimal DI container surface returned by mockContainer.

Wraps the same internal Container class the runtime uses for request scopes. Exposed under this alias so tests can annotate mocks without importing framework internals from deep paths.

Learn: Unit-test a controller

function mockContainer(services: ReadonlyMap<ServiceToken<FlareService>, FlareService>): Container

Constructs a minimal Container that resolves tokens from a developer-provided map.

Use for unit-testing controllers or services that take a Container in their constructor.

The fakes in the map are placed directly into the container’s singletons map, so resolveDep returns them immediately on the fast path. Missing deps surface at resolveDep time (via the standard "ServiceToken X not registered in container" error): loud and accurate, scoped to whichever token the test code actually tries to resolve.

services ReadonlyMap<ServiceToken<FlareService>, FlareService>

returns Container

Last updated: