So I'm unit-testing my code and I face a problem with testing an anonymous function being called inside the function that I'm unit-testing. The reason for why I didn't make the anonymous function an instance named function, is because I need the closure of some of the variables from the unit-tested function to be used inside the anonymous function. Example to illustrate:
function funcBeingTested(done, arg1) {
var self = this;
...
self.array.push({
"arguments": [
"x", "y", function (error, result) {
// do some stuff with arg1...
done(error, arg1);
}, "z"
]
});
...
self.run(); // Eventually will call the anonymous function above from 'self.array'
}
Now, my question is there a way to test what's going on inside that anonymous function using sinon.js ?
Someway I could call it with specific arguments as part of the unit test of funcBeingTested()
?
Aucun commentaire:
Enregistrer un commentaire