Function returnsArg

  • Creates a function that returns one of its arguments.

    Type Parameters

    • Arg

      The type of returned argument.

    • Self = any

      The self type of the returned function.

    Parameters

    • idx: number

      The index of the arguments to use.

    Returns ((this: Self, ...args: Arg[]) => Arg | undefined)

    A function that returns one of its arguments.

      • (this, ...args): Arg | undefined
      • Parameters

        Returns Arg | undefined

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

    const func = returnsArg(1);
    assertEquals(func(1, 2, 3), 2);