Function mock

  • Type Parameters

    • T extends (new (...args) => object)

    Parameters

    Returns T

    Description

    Functional alternative to the @Mockable() decorator. Returns the same class with prototype methods wrapped, without using decorator syntax.

    Example

    import { mock, SnapshotStore } from '@biorate/unimock';

    const MockedService = mock(RealService);
    const instance = new MockedService();
  • Type Parameters

    • T extends Record<string, any>

    Parameters

    Returns T

    Description

    Creates a snapshot-mocked copy of a plain object. The returned object has all methods wrapped for record/replay. The original object is not mutated.

    Example

    import { mock, SnapshotStore } from '@biorate/unimock';

    const obj = mock({ query: async (sql: string) => ({ data: [1] }) }, {
    importMeta: import.meta,
    });
    await obj.query('SELECT 1'); // recorded or replayed