jest-mock-aws
v1.1.0
Published
A prepared AWS mock to be used with jest.
Downloads
31
Readme
jest-mock-aws
Utiliy to help you mock AWS when testing with Jest.
You can use this only with the AWS Promise interface.
Quick start
npm install --save-dev jest-mock-aws
index.js
exports.publish = (message) => new AWS.SNS().publish(message).promise();
index.test.js
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');
});
API
mockAwsService
mockAwsService(AWS:object, serviceName:string) :object
const AWS = {};
const mockSns = mockAwsService(AWS, 'SNS');
mockSns.publish = jest.fn();
mockSns.publish.mockResolvedValue({});
mockAwsServiceMethod
mockAwsServiceMethod(AWS:object, serviceName:string, methodName:String) :jest.fn()
const AWS = {};
const mockSnsPublish = mockAwsServiceMethod(AWS, 'SNS', 'publish');
mockSnsPublish.mockResolvedValue({});
mockAwsServiceMethods
mockAwsServiceMethods(AWS:object, serviceName:string, methods:Array|Object) :object
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({});
});