I have a function with depends on another function and instead of testing the dependency I just want to test specific results of that dependency function. However, when I stub the function nothing happens and the return result is as if I never stubbed the function in the first place.
Example code:
// File being tested
function a() {
let str = 'test';
return b(str);
}
function b(str) {
return str + str;
}
module.exports = {
a: a,
b: b
};
// Test file
let test = require('file.to.test.js');
it('should correctly stub the b function', () => {
sinon.stub(test, 'b').returns('asdf');
let result = test.a();
// Expected
assert(result === 'asdf');
// Received
assert(result === 'testtest');
});