sinon stub not replacing function.
I tried a dummy module and to stub it, but does not work. the app.js function foo() { return run_func() } function run_func() { return '1' } exports._test = {foo: foo, run_func: run_func} the test.js app = require("./app.js")._test describe('test', function(){ it('test', function(){ var test_stub = sinon.stub(app, 'run_func').callsFake( function(){ return '0' }) test_stub.restore() var res = app.foo() assert.equal('0', res) }) }) I tried the advice from: sinon stub not replacing function But still the same. It does not replace the function. You have a couple of problems here. The first is that