Function stub

Properties

Properties

build: (<T>(init: RecursivePartial<T> | ((stub?: RecursivePartial<T>) => RecursivePartial<T>)) => ((stub?: RecursivePartial<T>) => T))

Type declaration

builder: (<T>(init: RecursivePartial<T> | ((stub?: RecursivePartial<T>) => RecursivePartial<T>)) => {
    create(): ((stub?: RecursivePartial<T>) => T);
    with(init: RecursivePartial<T> | ((stub?: RecursivePartial<T>) => RecursivePartial<T>)): { with(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)): ...; create(): (stub?: RecursivePartial<...> | undefined) => T; };
})

Type declaration

    • <T>(init): {
          create(): ((stub?: RecursivePartial<T>) => T);
          with(init: RecursivePartial<T> | ((stub?: RecursivePartial<T>) => RecursivePartial<T>)): { with(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)): ...; create(): (stub?: RecursivePartial<...> | undefined) => T; };
      }
    • Create a builder for a stub function of type T.

      The builder contains two methods:

      .with(): adds additional handler or partial stub. .create(): creates the final stub function.

      Type Parameters

      • T

      Parameters

      Returns {
          create(): ((stub?: RecursivePartial<T>) => T);
          with(init: RecursivePartial<T> | ((stub?: RecursivePartial<T>) => RecursivePartial<T>)): { with(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)): ...; create(): (stub?: RecursivePartial<...> | undefined) => T; };
      }

      • create:function
      • with:function
        • Adds an init object or handler to the builder.

          If init is an object, it will be merged with the stub object. If init is a function, it will be called with the stub object.

          Parameters

          Returns { with(init: RecursivePartial<T> | ((stub?: RecursivePartial<T> | undefined) => RecursivePartial<T>)): ...; create(): (stub?: RecursivePartial<...> | undefined) => T; }

          The builder instance.

      const b = stub.builder<{ a: number; b: string }>({ a: 1 }).with({ b: 'b' }).create()
      b({ a: 2 }) // { a: 2, b: 'b' }