JSPM

  • Created
  • Published
  • Downloads 269164
  • Score
    100M100P100Q176860F
  • License GPL-2.0

Functions to mock the JavaScript aws-sdk

Package Exports

  • aws-sdk-mock

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (aws-sdk-mock) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

aws-sdk-mock

AWSome mocks for Javascript aws-sdk services.

Build Status codecov.io Dependency Status devDependency Status

NPM

If you are new to Amazon WebServices Lambda (or need a refresher), please checkout our our
Beginners Guide to AWS Lambda: https://github.com/dwyl/learn-aws-lambda

Why?

Testing your code is essential everywhere you need reliability.

Using stubs means you can prevent a specific method from being called directly.

What?

Uses Sinon.js under the hood to mock the AWS SDK services and associated methods.

How? (Usage)

install aws-sdk-mock from NPM

npm install aws-sdk-mock --save-dev

Use in your Tests

import AWS from 'aws-sdk-mock';

AWS.mock('DynamoDB', 'putItem', function (params, callback){
  callback(null, "successfully put item in database");
});

AWS.mock('SNS', 'publish');

/**
    TESTS
**/

AWS.restore('SNS', 'publish');
AWS.restore('DynamoDB');
// or AWS.restore(); this will restore all the methods and services 

Documentation

AWS.mock(service, method, replace)

Replaces a method on an AWS service with a replacement function or string.

  • service: AWS service to mock e.g. SNS, DynamoDB, S3
  • method : method on AWS service to mock e.g. 'publish' (for SNS), 'putItem' for 'DynamoDB'
  • replace : a string or function to replace the method

AWS.restore(service, method)

Removes the mock to restore the specified AWS service

Optional:

  • service : AWS service to restore - If only the service is specified, all the methods are restored
  • method : Method on AWS service to restore

If no arguments are given to AWS.restore then all the services and their associated methods are restored i.e. equivalent to a 'restore all' function.

Background Reading