Skip to content

Instantly share code, notes, and snippets.

@svlapin
Created November 3, 2017 16:15
Show Gist options
  • Save svlapin/77c3844f5231d390b72725cf929562c7 to your computer and use it in GitHub Desktop.
Save svlapin/77c3844f5231d390b72725cf929562c7 to your computer and use it in GitHub Desktop.
An example on how to stub git-js methods
const sinon = require('sinon');
const Git = require('simple-git/src/git');
const git = require('simple-git/promise');
sinon.stub(Git.prototype, '_run').callsFake(function (command, cb) {
console.log('called command', command)
// to indicate success
cb.call(this, null, 'any message');
return this;
});
git().pull('origin', 'master')
.then(() => {
console.log('all done, success');
})
.catch((err) => {
console.log('error:', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment