Let's say, I have app.js
function method(){
return true;
}
function callMethod(){
return method();
}
module.exports.method = method;
module.exports.callMethod = callMethod;
And app.spec.js
var app = require(app);
...describe code etc...
var first = sinon.spy(app,'callMethod');
var second = sinon.spy(app,'method');
app.callMethod();
expect(first.called).to.equal(true); //passed
expect(second.called).to.equal(true); //fails
I'm guessing it's failing because inside my spec file I have a different reference to 'method' than the one that is being called when inside app.js calls it from inside of 'callMethod'.
I've seen this behavior many times before, and I know work arounds, but I was wondering if there was a clean way to actually spy on the method 'method' in this situation without a workaround.