Function capture

  • Intercept calls to a method to track the arguments, call site, and return/throw status, and replace the implementation.

    By default, the method is set to a no-op. To retain the method behavior, pass the current value of the method as the third argument. For example:

    const results = t.capture(obj, 'foo', obj.foo)
    

    Automatically restores at t.teardown() if the @tapjs/after plugin is not disabled. Otherwise, it is important to call the restore() method on the returned function when you are done capturing.

    Type Parameters

    • T extends {}
    • M extends string | number | symbol

    Parameters

    • obj: T
    • method: M
    • Optionalimpl: ((this: T, ...a: any[]) => any)
        • (this, ...a): any
        • Parameters

          • this: T
          • Rest...a: any[]

          Returns any

    Returns CaptureResultsMethod<T, M, T[M]>