//Class under test
var AWS = require('aws-sdk');
var s3Export = function() {
var s3Client = new AWS.S3();
this.getObject => (params) => {
return s3Client.getObject(params).promise();
}
};
module.exports.S3 = new s3Export();
// Test Class
describe('s3-wrapper-tests', function() {
var app, aws, s3, getObjectData = {Bucket: 'test-bucket', Key: 'test-file'}, deleteObjectData,
deleteObjectsDatas, putObject;
before(() => {
s3 = sinon.stub({
getObject: function(params) {
getObjectData = params;
return Promise.resolve( {Body: ['a','b','c']} );
});
aws = sinon.stub(AWS, 'S3');
aws.returns(s3);
app = proxyquire(modulePath, {'aws-sdk': aws } );
});
after(() => {
aws.restore();
});
beforeEach(() => {
s3.getObject.reset();
s3.getObject.callsArgWith(0, getObjectData);
});
it('test message', () => {
return app.S3.getObject(
{Bucket: 'test-bucket', Key: 'test-file'}).then(() => {
const args = s3.getObject.getCall(0).args[0];
expect(args).to.not.be.null;
});
});
});
The question I have is on Sinon's callsWithArgs method and the promise's aws-sdk. My question, how can I test this call was made with the correct parameters and return a promise as expected. As it stands now the test fails with Exception:
TypeError: argument at index 1 is not a function: undefined