Some code would be good, but usually this can be achieved like this (using mocha)
describe('A test', function() {
beforeEach(function() {
// what you want to stub is passed as a string
sinon.stub(ExecSync, 'sh').yields(null,40);
});
afterEach(function() {
ExecSync.restore();
});
it('has behaviour', function() {
ExecSync.sh(function(err, res) {
// err = null, res = 40
});
});
});
Another common practice when you cannot stub a dependency, is to write that dependency onto your module under test, such as
mymodule.ExecSync = function(arg) {
ExecSync.sh(arg);
};
Then you can simply stub ExecSync on your module and never have to call the dependency at all.