javascript - How to stub aws-sdk -


lets have following

// file sample.js var aws = require('aws-sdk'); var dynamodb = new aws.dynamodb();  exports.processdata = function(){   var data = dynamodb.getitem(params);   // data }; 

how can write unit tests above code sample.

//file sample_test.js var aws = require('aws-sdk'); var sinon = require('sinon');  // following code doesnt seem stub function // actual function still used in sample.js var getitemstub = sinon.stub(); aws.dynamodb.prototype.getitem = getitemstub;  var sample = require('./sample'); 

what way stub aws-sdk api. thinking of using sinonjs achieve it, open other libraries , suggestions .

we have created aws-sdk-mock npm module mocks out aws sdk services , methods. https://github.com/dwyl/aws-sdk-mock

it's easy use. call aws.mock service, method , stub function.

aws.mock('dynamodb', 'getitem', function(params, callback) {     callback(null, 'success'); }); 

then restore methods after tests calling:

aws.restore('dynamodb', 'getitem'); 

or restore them call:

aws.restore(); 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -