mardi 30 juin 2015

Unit Testing: Check whether an internal function was called or not? Using Sinon and Chai

Consider log.js has function:

var function processData()
{
     if(condition)
          dbInsert();
}

var function dbInsert()
{
  // do some insertion
}

Now I want to test that when processData is called whether dbInsert is called or not. This is my test.js. Which fails test on the last one although when I manually check the db there does exist an entry

it('internal function called or not', function() {

    var Data = '{"id":"123","name":"xyz"}';

    var spy = sinon.spy(log, "processData");
    var spy2 = sinon.spy(log, "dbInsert");



    log.processData(Data);                 

    expect(spy.callCount).to.be.equal(1);
    expect(spy2.called).to.be.true;   // returns false .. 

});

Aucun commentaire:

Enregistrer un commentaire