Nobody Preheats Microwaves

    jest-mock-aws

    1.1.0 • Public • Published

    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({});
    });

    Keywords

    Install

    npm i jest-mock-aws

    DownloadsWeekly Downloads

    127

    Version

    1.1.0

    License

    MIT

    Unpacked Size

    5.67 kB

    Total Files

    4

    Last publish

    Collaborators

    • moeriki