Many node modules export a single function (not a constructor function, but a general purpose "utility" function) as its "module.exports". Is it possible to use Sinon.js to stub this standalone function?
// some module, "sum.js" that's "required" throughout the application
module.exports = function(a, b) {
return a + b;
};
// test.js
var sum = require('sum');
...
beforeEach(function() {
sumStub = sinon.stub(sum);
// throws: TypeError: Attempted to wrap undefined property undefined as function
});
afterEach(function() {
sumStub.restore();
});
...
Is there any way to achieve this?
Many node modules export a single function (not a constructor function, but a general purpose "utility" function) as its "module.exports". Is it possible to use Sinon.js to stub this standalone function?
Is there any way to achieve this?