Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing within a javascript closure

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?

like image 370
superluminary Avatar asked Jul 08 '11 14:07

superluminary


1 Answers

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$

like image 62
Manux Avatar answered Sep 16 '22 22:09

Manux