Up until now I have been using sinon to stub out function calls on objects included in my nodeJS code.
For example I use the request library, and so in my tests I can stub out http calls like:
var request = require('request');
//Somewhere further below in my tests:
postStub = sinon.stub(request, 'post');
I have now hit a scenario where a library I am including needs to be called like so in my actual code:
var archiver = require('archiver');
//Further below in actual code (express middleware)
var zip = archiver('zip');
zip.pipe(res);
I want to be able to stub out calls to pipe()
on the archiver library, but I think I need to stub out the constructor call first - archiver('zip')
?
I have had a search around and I think sinon's createStubInstance could help me here, but I am not 100% sure.
Can someone assist? Thanks