Is it possible to unit test javascript functions that exist within a closure, so for example, given the following:
(function() {
var a = function() {
//do something
}
window.b = function() {
// do something else
}
})();
Is it possible to unit test function a without exposing it? If not, is there a good way to expose a, but only in test mode?
Your anonymous function could take a parameter which would be undefined when not in test mode, and say this parameter would be an object, you could fill the object with a
's without exposing a
directly.
Just my .02$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With