Class CommandBehavior<TInput, TOutput, TCommandOutput, TConfiguration>

Type Parameters

  • TInput extends object

  • TOutput extends MetadataBearer

  • TCommandOutput extends TOutput

  • TConfiguration

Hierarchy

  • CommandBehavior

Implements

  • Behavior<TInput, TOutput, TCommandOutput, TConfiguration>

Constructors

  • Type Parameters

    • TInput extends object

    • TOutput extends MetadataBearer

    • TCommandOutput extends MetadataBearer

    • TConfiguration

    Parameters

    • clientStub: AwsStub<TInput, TOutput, TConfiguration>
    • send: SinonStub<[AwsCommand<TInput, TOutput, any, any>], unknown>

    Returns CommandBehavior<TInput, TOutput, TCommandOutput, TConfiguration>

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, TCommandOutput, TConfiguration>

  • 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

    • Optional strict: boolean

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

    Returns Behavior<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, TCommandOutput, 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<TCommandOutput>

      Content to be returned

    Returns CommandBehavior<TInput, TOutput, TCommandOutput, TConfiguration>

Generated using TypeDoc