title: Unit testing self-invoking functions
body: <p>I have a self-invoking function in a JavaScript file. Something like this:</p>
  
  <pre><code>com.renderer = (function(){
  
      render(data){
  
      }
  
      .....other functions 
  
      return{
  
          init : function(){
              $(document).ready(function(){
                jsonData = fetchFromServer();
                render(jsonData);
              });
  
           }
      }
  
  })().init();
  </code></pre>
  
  <p>I am thinking of how to unit test this. I am using JSUnitTestDriver. If I could somehow inject <code>jsonData</code> to the render function from outside, that would be good, but that seems impossible to me.</p>
  
  <p>Any suggestions or alternatives? </p>
  
  <p>I really do not want to remove the self-invoking nature of the function. And does it really make sense to change what I consider good design for the sake of unit tests? (In this particular case, not in general.)</p>
  
  <p>Note: I can't talk to a server while running tests.</p>