Setu-TS
    Preparing search index...

    Function createMockPlugin

    • 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).

      Parameters

      Returns IPlugin

      An IPlugin that registers the mock service

      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).

      0.1.0