Underlying Client#send()
method Sinon stub.
Install @types/sinon
for TypeScript typings.
Returns n-th recorded call to the stub.
Returns recorded calls to the stub. Clear history with resetHistory or reset.
Sets a function that will be called on any Client#send()
invocation.
Function taking Command input and returning result
snsMock
.callsFake(input => {
if (input.Message === 'My message') {
return {MessageId: '111'};
} else {
throw new Error('mocked rejection');
}
});
Result based on the Client
configuration:
snsMock
.callsFake(async (input, getClient) => {
const client = getClient();
const region = await client.config.region();
return {MessageId: region.substring(0, 2)};
});
Sets a function that will be called once, 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()
.
Function taking Command input and returning result
snsMock
.callsFakeOnce(cmd => {MessageId: '111'}) // first call
.callsFakeOnce(cmd => {MessageId: '222'}) // second call
.callsFake(cmd => {MessageId: '000'}); // default
Returns recorded calls of given Command only.
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.
Command type to match
Optional
input: Partial<TCmdInput>Command payload to match
Should the payload match strictly (default false, will match if all defined payload properties match)
snsMock
.on(PublishCommand, {Message: 'My message'})
.resolves({MessageId: '111'});
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.
Optional
input: Partial<TCmdInput>Command payload to match
Should the payload match strictly (default false, will match if all defined payload properties match)
clientMock.onAnyCommand().resolves({})
Sets a failure response that will be returned from any Client#send()
invocation.
The response will always be an Error
instance.
Optional
error: string | Error | AwsErrorError text, Error instance or Error parameters to be returned
snsMock
.rejects('mocked rejection');
const throttlingError = new Error('mocked rejection');
throttlingError.name = 'ThrottlingException';
snsMock
.rejects(throttlingError);
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()
.
Optional
error: string | Error | AwsErrorError text, Error instance or Error parameters to be returned
snsMock
.rejectsOnce('first mocked rejection')
.rejectsOnce('second mocked rejection')
.rejects('default mocked rejection');
Resets stub. It will replace the stub with a new one, with clean history and behavior.
Resets stub's calls history.
Sets a successful response that will be returned from any Client#send()
invocation.
Content to be returned
snsMock
.resolves({MessageId: '111'});
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()
.
Content to be returned
snsMock
.resolvesOnce({MessageId: '111'}) // first call
.resolvesOnce({MessageId: '222'}) // second call
.resolves({MessageId: '333'}); // default
Wrapper on the mocked
Client#send()
method, allowing to configure its behavior.Without any configuration,
Client#send()
invocation returnsundefined
.To define resulting variable type easily, use AwsClientStub.