Function taking Command input and returning result
snsMock
.on(PublishCommand)
.callsFake(input => {
if (input.Message === 'My message') {
return {MessageId: '111'};
} else {
throw new Error('mocked rejection');
}
});
Result based on the Client
configuration:
snsMock
.on(PublishCommand)
.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 Client#send()
invocation for the current Command
.
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
.on(PublishCommand)
.callsFakeOnce(cmd => {MessageId: '111'}) // first call
.callsFakeOnce(cmd => {MessageId: '222'}) // second call
.callsFake(cmd => {MessageId: '000'}); // default
Optional
input: Partial<TCmdInput>Using this method means that the previously set .on(Command)
was not followed by resolves/rejects/callsFake call.
If this is legitimate behavior, please open an issue with your use case.
Optional
input: Partial<TCmdInput>Optional
strict: booleanUsing this method means that the previously set .on(Command)
was not followed by resolves/rejects/callsFake call.
If this is legitimate behavior, please open an issue with your use case.
Sets a failure response that will be returned from Client#send()
invocation for the current Command
.
The response will always be an Error
instance.
Optional
error: string | Error | AwsErrorError text, Error instance or Error parameters to be returned
snsMock
.on(PublishCommand)
.rejects('mocked rejection');
const throttlingError = new Error('mocked rejection');
throttlingError.name = 'ThrottlingException';
snsMock
.on(PublishCommand)
.rejects(throttlingError);
Sets a failure response that will be returned from one Client#send()
invocation for the current Command
.
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
.on(PublishCommand)
.rejectsOnce('first mocked rejection')
.rejectsOnce('second mocked rejection')
.rejects('default mocked rejection');
Sets a successful response that will be returned from Client#send()
invocation for the current Command
.
Content to be returned
snsMock
.on(PublishCommand)
.resolves({MessageId: '111'});
Sets a successful response that will be returned from one Client#send()
invocation for the current Command
.
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
.on(PublishCommand)
.resolvesOnce({MessageId: '111'}) // first call
.resolvesOnce({MessageId: '222'}) // second call
.resolves({MessageId: '333'}); // default
Sets a function that will be called on
Client#send()
invocation for the currentCommand
.