Utiliy to help you mock AWS when testing with Jest.
You can use this only with the AWS Promise interface.
npm install --save-dev jest-mock-aws
exports.publish = (message) => new AWS.SNS().publish(message).promise();
const AWS = require('aws-sdk');
const { mockAwsServiceMethod } = require('jest-mock-aws');
jest.mock('aws-sdk', () => ({}));
it('should mock AWS', () => {
const mockPublish = mockAwsServiceMethod(AWS, 'SNS', 'publish');
mockPublish.mockResolvedValue('publish-result');
});
const AWS = {};
const mockSns = mockAwsService(AWS, 'SNS');
mockSns.publish = jest.fn();
mockSns.publish.mockResolvedValue({});
const AWS = {};
const mockSnsPublish = mockAwsServiceMethod(AWS, 'SNS', 'publish');
mockSnsPublish.mockResolvedValue({});
With Array.
const AWS = {};
const mockSqs = mockAwsServiceMethods(AWS, 'SQS', [
'deleteMessage',
'receiveMessages',
]);
mockSqs.deleteMessage.mockResolvedValue({});
mockSqs.receiveMessages.mockResolvedValue({});
With Object.
const AWS = {};
const mockSqs = mockAwsServiceMethods(AWS, 'SQS', {
deleteMessage: jest.fn().mockResolvedValue({});
receiveMessages: jest.fn().mockResolvedValue({});
});