function createMockPlugin
Since 0.1.0
createMockPlugin(options: MockPluginOptions): IPlugin

Creates an IPlugin that registers a mock service under a capability token.

Collapses the boilerplate of writing a one-line plugin literal ({ name, provides: [...], register(ctx) { ctx.services.register(...) } }) into a single call. The plugin uses options.name as the default capability token (overridable via options.provides).

Examples

Example 1

import { createMockPlugin } from '@setu-ts/testing';
import { CAPABILITIES } from '@setu-ts/common';

const mockDb = createMockPlugin({
  name: 'database',
  service: { query: () => [], connect: () => {} },
});

// Consumed as ctx.services.get<Idb>(CAPABILITIES.DATABASE);

This PROVIDES a capability; it cannot REPLACE one. The returned plugin declares the token in provides, which is what lets a dependent plugin's dependencies check pass — and which the kernel refuses when a real plugin already declares it (Capability 'database' is provided by both 'database' and 'database-mock'), before any plugin runs. Use it in an application that does not register the real plugin. To substitute a double into one that does, use overrideCapability(token, service).

Parameters

Mock plugin configuration

Return Type

IPlugin

An IPlugin that registers the mock service

Usage

import { createMockPlugin } from "testing/src/index.ts";