I discovered the answer after having typed out the entire question, just before pressing submit.
I solved it by initialising Client
as an empty object and then stubbing the describeInstances
method on it:
var ec2Stub = gently.stub("aws-sdk", "EC2"),
ec2;
gently.expect(ec2Stub, "new", function () {
ec2 = this;
});
moduleFoo.initEC2Client();
ec2.Client = {};
gently.expect(ec2.Client, "describeInstances", function (params, callback) {
// assert `params` is populated ok
callback();
})
moduleFoo.doSomething();
gently.verify(); // throws no error