Function returnsThis

  • Creates a function that returns the instance the method was called on.

    Type Parameters

    • Self = any

      The self type of the returned function.

    • Args extends unknown[] = any[]

      The arguments type of the returned function.

    Returns ((this: Self, ...args: Args) => Self)

    A function that returns the instance the method was called on.

    import { returnsThis } from "@std/testing/mock";
    import { assertEquals } from "@std/assert";

    const func = returnsThis();
    const obj = { func };
    assertEquals(obj.func(), obj);