Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • SinonFake

Callable

  • SinonFake<TArgs, TReturnValue>(): SinonSpy<TArgs, TReturnValue>
  • SinonFake<TArgs, TReturnValue>(fn: (...args: TArgs) => TReturnValue): SinonSpy<TArgs, TReturnValue>
  • Creates a basic fake, with no behavior

    Type parameters

    • TArgs: readonly any[] = any[]

    • TReturnValue = any

    Returns SinonSpy<TArgs, TReturnValue>

  • Wraps an existing Function to record all interactions, while leaving it up to the func to provide the behavior. This is useful when complex behavior not covered by the sinon.fake.* methods is required or when wrapping an existing function or method.

    Type parameters

    • TArgs: readonly any[] = any[]

    • TReturnValue = any

    Parameters

    • fn: (...args: TArgs) => TReturnValue
        • (...args: TArgs): TReturnValue
        • Parameters

          • Rest ...args: TArgs

          Returns TReturnValue

    Returns SinonSpy<TArgs, TReturnValue>

Index

Methods

rejects

  • rejects<TArgs, TReturnValue>(val: any): SinonSpy<TArgs, TReturnValue>
  • Creates a fake that returns a rejected Promise for the passed value. If an Error is passed as the value argument, then that will be the value of the promise. If any other value is passed, then that will be used for the message property of the Error returned by the promise.

    Type parameters

    • TArgs: readonly any[] = any[]

    • TReturnValue = any

    Parameters

    • val: any

      Rejected promise

    Returns SinonSpy<TArgs, TReturnValue>

resolves

  • resolves<TArgs, TReturnValue>(val: TReturnValue extends PromiseLike<TResolveValue> ? TResolveValue : any): SinonSpy<TArgs, TReturnValue>
  • Creates a fake that returns a resolved Promise for the passed value.

    Type parameters

    • TArgs: readonly any[] = any[]

    • TReturnValue = any

    Parameters

    • val: TReturnValue extends PromiseLike<TResolveValue> ? TResolveValue : any

      Resolved promise

    Returns SinonSpy<TArgs, TReturnValue>

returns

  • returns<TArgs, TReturnValue>(val: TReturnValue): SinonSpy<TArgs, TReturnValue>
  • Creates a fake that returns the val argument

    Type parameters

    • TArgs: readonly any[] = any[]

    • TReturnValue = any

    Parameters

    • val: TReturnValue

      Returned value

    Returns SinonSpy<TArgs, TReturnValue>

throws

  • throws<TArgs, TReturnValue>(val: string | Error): SinonSpy<TArgs, TReturnValue>
  • Creates a fake that throws an Error with the provided value as the message property. If an Error is passed as the val argument, then that will be the thrown value. If any other value is passed, then that will be used for the message property of the thrown Error.

    Type parameters

    • TArgs: readonly any[] = any[]

    • TReturnValue = any

    Parameters

    • val: string | Error

      Returned value or throw value if an Error

    Returns SinonSpy<TArgs, TReturnValue>

yields

  • yields<TArgs, TReturnValue>(...args: any[]): SinonSpy<TArgs, TReturnValue>
  • fake expects the last argument to be a callback and will invoke it with the given arguments.

    Type parameters

    • TArgs: readonly any[] = any[]

    • TReturnValue = any

    Parameters

    • Rest ...args: any[]

    Returns SinonSpy<TArgs, TReturnValue>

yieldsAsync

  • yieldsAsync<TArgs, TReturnValue>(...args: any[]): SinonSpy<TArgs, TReturnValue>
  • fake expects the last argument to be a callback and will invoke it asynchronously with the given arguments.

    Type parameters

    • TArgs: readonly any[] = any[]

    • TReturnValue = any

    Parameters

    • Rest ...args: any[]

    Returns SinonSpy<TArgs, TReturnValue>