@figentra/testing eliminates that boilerplate by shipping a focused set of utilities that integrate seamlessly with Vitest and the rest of the Figentra ecosystem. Import what you need, write the test, ship it.
Installation
Install@figentra/testing as a development dependency — it should never appear in production bundles.
Always install
@figentra/testing as a devDependency. It depends on
Vitest internals and test-only shims that must not be included in production
builds. If you accidentally add it as a regular dependency, your production
bundle size will increase and you may see runtime errors in non-test
environments.What’s Included
createMockContainer
Creates a pre-wired
Container instance populated with the mock services
you supply. Ideal for unit-testing services that accept a container as a
dependency.mockLogger
A no-op logger that satisfies the
Logger interface while silently
recording every call. Inspect .calls in your assertions without polluting
test output.createTestFixture<T>
A strongly-typed factory for test data. Define a default shape once, then
call
.build(overrides) in each test to produce a variant with only the
fields that matter.waitForCondition
An async polling helper that repeatedly evaluates a predicate until it
returns
true or a configurable timeout elapses. Keeps integration tests
free of arbitrary setTimeout calls.Usage Examples
Mock Container
UsecreateMockContainer when the system-under-test resolves dependencies from a container. Pass an object whose keys are token strings and whose values are partial mock implementations — Vitest spy functions work perfectly here.
Mock Logger
ImportmockLogger directly when your service accepts a logger instance rather than a full container.
Test Fixture
createTestFixture returns a factory bound to a default object shape. Call .build() to get the default, or .build(overrides) to merge in specific field values.
waitForCondition
UsewaitForCondition in integration tests where an action triggers an async side-effect — a database write, an event emission, a queue message — that you need to assert against without knowing exactly when it will complete.
API Reference
createMockContainer(services)
Container instance pre-populated with the provided mock services. Each key in services is registered as a singleton under the matching string token.
mockLogger()
Logger interface. All methods are no-ops; each call is appended to the corresponding array under .calls for later assertion.
createTestFixture<T>(defaults)
defaults. Call .build() to get the default object, or .build(overrides) to return a shallow-merged copy with the specified fields replaced.
waitForCondition(predicate, options?)
predicate every intervalMs milliseconds (default 100) until it returns true or timeoutMs milliseconds (default 5000) elapses. Throws a TimeoutError if the predicate never becomes truthy within the timeout.