Suppose you have the following JS function:
function YourProxy($orm, $usr) {
this.addToDB = function(obj) {
return function(callback){
var oo = $orm.createNew(obj);
oo.save(options, function(err,ok){
if(err) callback(err);
callback(null,ok);
}
}
}
}
which you can use in node.js with ES6 generators to wait for this operation to happen with something like:
function *(){
var yourProxy = new YourProxy();
try {
var result = yield yourProxy.addToDB(anObject);
} catch(e) {
}
}
To verify that I did something similar using mocha and sine (and mocha-sine):
describe('addToDB', function(){
it('adds the object to the db', function(){
var callback = sinon.spy();
myProxy.addToDB(anObject)(callback);
expect( callback ).to.be.calledOnce;
});
});
but all i got is that callback is never called because addToDB () exits before calling the save call.
How would you test this?
source
share