jeudi 8 octobre 2015

Sinon Stub is not working in mocha

I am trying to use sinon stub to mock a function but its not working as expected, can some one explain how to fix it

In one of the file customFunc.js I have functions like

function test() {
  return 'working good';
}
exports.test = test;

function testFunction(data, callback) {
  var sample = test();
  if(sample === 'test') {
    return callback(null, sample);
  }
  else {
    return callback(null, 'not working');
  }
}
exports.testFunction = testFunction;

and I am trying to test testFunction using mocha and I tried to stub test function using sinon like this

it('testing sinon', function(done) {
  var stub = sinon.stub(customFunc,'test').returns('working');

  customFunc.testFunction('test', function(err, decodedPayload) {
    decodedPayload.should.equal('working');
    done();
  });
});

Is sinon works I should always get 'working' as output but its not happening, please let me know how to mock test() function.

Aucun commentaire:

Enregistrer un commentaire