title: How can I test unit test my jQuery-based code?
body: <p>I have following code in a file named index.js. I want to test some functions in it <code>add</code>, <code>print</code> being the prime one.</p>
  
  <pre><code>(function($){
    "use strict";
  
    $(function(){
  
      var add = function(a, b){
      // ...
        },
      print = function(str){
      // ...
        },
        setup = function(){
      // ...
        },
        init = function(){
      // ...
        };
  
        setup();
        init();
    });
  })(jQuery);
  </code></pre>
  
  <p>How can I do so?
  Does this way of coding add any security on client side? All I have is code that runs on the client side. No server involvement what-so-ever.</p>
  
  <p>I tried :</p>
  
  <pre><code>var outerObj = (function(greet){
      var innerObj = (function(){
          return {test: function(){ console.log(greet); }}
      })();
      return innerObj;
  })("hi");
  
  outerObj.test();
  </code></pre>
  
  <p>but, in my case, <code>innerObj</code> line has a <code>$</code> on the right hand of equal sign, making console yell error that shouts <strong>$(...) is not a function</strong>. 
  Which I agree, it's an array of single document object.</p>
  
  <p>Check out <code>var a = (function(){ var val = $(function(){return 10;})(); })();</code> in any jquery enabled web-page's console, for the error.</p>
  
  <p>Even if I ditch outer shell and bring <code>$(function() {});</code> out. How am I gonna test that? </p>
  
  <p>It's still an object, still an error.</p>
  
  <p>What kind of testing can I perform, unit, bdd, etc. and how?</p>