I have a self-invoking function in a JavaScript file. Something like this:
com.renderer = (function(){
render(data){
}
.....other functions
return{
init : function(){
$(document).ready(function(){
jsonData = fetchFromServer();
render(jsonData);
});
}
}
})().init();
I am thinking of how to unit test this. I am using JSUnitTestDriver. If I could somehow inject jsonData
to the render function from outside, that would be good, but that seems impossible to me.
Any suggestions or alternatives?
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.)
Note: I can't talk to a server while running tests.