0
Dies ist mein Code: start_end.jsWie in node.js Variable mit Sinon/Mokka verspotten
var glb_obj, test={};
var timer = 10;
test.start_pool = function(cb) {
timer--;
if(timer < 1) {
glb_obj = {"close": true}; // setting object
cb(null, "hello world");
} else {
start_pool(cb);
}
}
test.end_pool = function(){
if(glb_obj && glb_obj.close) {
console.log("closed");
}
}
module.exports = test;
Testfall:
var sinon = require('sinon');
var start_end = require('./start_end');
describe("start_end", function(){
before(function() {
cb_spy = sinon.spy();
});
afterEach(function() {
cb_spy.reset();
});
it("start_pool()", function(done){
// how to make timer variable < 1, so that if(timer < 1) will meet
start_end.start_pool(cb_spy);
sinon.assert.calledWith(cb_spy, null, "hello world");
});
});
wie die Variable timer
und glb_obj
innerhalb der Funktionen ändern mit Sinon?