Class AwsStub<TInput, TOutput, TConfiguration>

Wrapper on the mocked Client#send() method, allowing to configure its behavior.

Without any configuration, Client#send() invocation returns undefined.

To define resulting variable type easily, use AwsClientStub.

Type Parameters

  • TInput extends object

  • TOutput extends MetadataBearer

  • TConfiguration

Hierarchy

  • AwsStub

Implements

  • Behavior<TInput, TOutput, TOutput, TConfiguration>

Constructors

  • Type Parameters

    • TInput extends object

    • TOutput extends MetadataBearer

    • TConfiguration

    Parameters

    • client: Client<TInput, TOutput, TConfiguration>
    • send: SinonStub<[AwsCommand<TInput, TOutput, any, any>], Promise<TOutput>>

    Returns AwsStub<TInput, TOutput, TConfiguration>

Properties

send: SinonStub<[AwsCommand<TInput, TOutput, any, any>], Promise<TOutput>>

Underlying Client#send() method Sinon stub.

Install @types/sinon for TypeScript typings.

Methods

  • Sets a function that will be called on any Client#send() invocation.

    Parameters

    • fn: ((input: any, getClient: (() => Client<TInput, TOutput, TConfiguration>)) => any)

      Function taking Command input and returning result

        • (input: any, getClient: (() => Client<TInput, TOutput, TConfiguration>)): any
        • Parameters

          • input: any
          • getClient: (() => Client<TInput, TOutput, TConfiguration>)
              • (): Client<TInput, TOutput, TConfiguration>
              • Returns Client<TInput, TOutput, TConfiguration>

          Returns any

    Returns AwsStub<TInput, TOutput, TConfiguration>

  • Sets a function that will be called on any Client#send() invocation.

    Can be chained so that successive invocations call different functions. When there are no more callsFakeOnce() functions to use, invocations will call a function specified by callsFake().

    Example

    clientMock
    .callsFakeOnce(cmd => 'first call')
    .callsFakeOnce(cmd => 'second call')
    .callsFake(cmd => 'default');

    Parameters

    • fn: ((input: any, getClient: (() => Client<TInput, TOutput, TConfiguration>)) => any)

      Function taking Command input and returning result

        • (input: any, getClient: (() => Client<TInput, TOutput, TConfiguration>)): any
        • Parameters

          • input: any
          • getClient: (() => Client<TInput, TOutput, TConfiguration>)
              • (): Client<TInput, TOutput, TConfiguration>
              • Returns Client<TInput, TOutput, TConfiguration>

          Returns any

    Returns CommandBehavior<TInput, TOutput, TOutput, TConfiguration>

  • Returns recorded calls of given Command only.

    Type Parameters

    • TCmd extends Command<any, any, any, any, any, TCmd>

    • TCmdInput extends any

    • TCmdOutput extends any

    Parameters

    • commandType: (new (input: TCmdInput) => TCmd)

      Command type to match

        • new (input: TCmdInput): TCmd
        • Parameters

          • input: TCmdInput

          Returns TCmd

    • Optional input: Partial<TCmdInput>

      Command payload to match

    • Optional strict: boolean

      Should the payload match strictly (default false, will match if all defined payload properties match)

    Returns SinonSpyCall<[TCmd], Promise<TCmdOutput>>[]

  • Allows specifying the behavior for a given Command type and its input (parameters).

    If the input is not specified, it will match any Command of that type.

    Type Parameters

    • TCmdInput extends object

    • TCmdOutput extends MetadataBearer

    Parameters

    • command: (new (input: TCmdInput) => AwsCommand<TCmdInput, TCmdOutput, any, any>)

      Command type to match

        • new (input: TCmdInput): AwsCommand<TCmdInput, TCmdOutput, any, any>
        • Parameters

          • input: TCmdInput

          Returns AwsCommand<TCmdInput, TCmdOutput, any, any>

    • Optional input: Partial<TCmdInput>

      Command payload to match

    • strict: boolean = false

      Should the payload match strictly (default false, will match if all defined payload properties match)

    Returns CommandBehavior<TInput, TOutput, TCmdOutput, TConfiguration>

  • Allows specifying the behavior for any Command with given input (parameters).

    If the input is not specified, the given behavior will be used for any Command with any input.

    Calling onAnyCommand() without parameters is not required to specify the default behavior for any Command, but can be used for readability.

    Example

    clientMock.onAnyCommand().resolves(123)
    

    is same as:

    clientMock.resolves(123)
    

    Type Parameters

    • TCmdInput extends object

    Parameters

    • Optional input: Partial<TCmdInput>

      Command payload to match

    • strict: boolean = false

      Should the payload match strictly (default false, will match if all defined payload properties match)

    Returns CommandBehavior<TInput, TOutput, TOutput, TConfiguration>

  • Sets a failure response that will be returned from one Client#send() invocation. The response will always be an Error instance.

    Can be chained so that successive invocations return different responses. When there are no more rejectsOnce() responses to use, invocations will return a response specified by rejects().

    Example

    clientMock
    .rejectsOnce('first call')
    .rejectsOnce('second call')
    .rejects('default');

    Parameters

    • Optional error: string | Error | AwsError

      Error text, Error instance or Error parameters to be returned

    Returns CommandBehavior<TInput, TOutput, TOutput, TConfiguration>

  • Sets a successful response that will be returned from one Client#send() invocation.

    Can be chained so that successive invocations return different responses. When there are no more resolvesOnce() responses to use, invocations will return a response specified by resolves().

    Example

    clientMock
    .resolvesOnce('first call')
    .resolvesOnce('second call')
    .resolves('default');

    Parameters

    • response: CommandResponse<TOutput>

      Content to be returned

    Returns CommandBehavior<TInput, TOutput, TOutput, TConfiguration>

Generated using TypeDoc