Skip to content

Instantly share code, notes, and snippets.

View jaspervalero's full-sized avatar

Jasper Valero jaspervalero

View GitHub Profile
@jaspervalero
jaspervalero / index.js
Created February 23, 2018 20:01 — forked from joerx/index.js
Mocking S3 in Node.js using Sinon
var Aws = require('aws-sdk');
var sinon = require('sinon');
// Only works for 'createBucket', 'update' and a few others since most API methods are generated dynamically
// upon instantiation. Very counterintuitive, thanks Amazon!
var createBucket = sinon.stub(Aws.S3.prototype, 'createBucket');
createBucket.yields(null, 'Me create bucket');
// For other methods, we can 'assign' the stubs to the proto, already defined function won't be overridden
var listBuckets = Aws.S3.prototype.listBuckets = sinon.stub();