samedi 28 mars 2015

Testing private functions using eval

I'm writing a node module and I want to be able to unit test all my functions, however I have not exposed many of them (shown below).



module.exports = function() {
var privateFunction = function() {
// Do Stuff Here
};
return {
publicFunction: function() {
// do stuff
privateFunction();
}
}
}


I read on another stack question that eval could be used if my private functions were moved to the global scope, that way my functions would be interpreted and could be tested. Despite eval being generally considered bad practice, I can't really see another method of testing these functions.


Does anyone know of a better method to test these.


Aucun commentaire:

Enregistrer un commentaire