views:

63

answers:

1

I am currently trying to create a test suite for my javascript apps. My problem is that, it seems I cannot get access to init() from my utils object, as you can see below:

I have my app that follow a singleton pattern:

var appModal = function () {
    var utils = Object.create(moduleUtils);
     function init(caller, options ) {
    }
}();

My test suite is in moduleUtils, this is a object literal converted to a prototype

moduleUtils.debug = {
    addSlideTest : function(){
        /* this function cannot fire init() from appModal */
}}
+1  A: 

This is not possible.
You need to expose the closured functions in a publicly visible object.

For example, you can make a testMethods object in your unit tests to collect private methods. Your main file would then add private methods to the object if it exists, like this:

//In appModal
if (typeof testMethods === "object")
    testMethods.init = init;

//In test suite
testMethods = { };
...
testMethods.init();
SLaks
this is not perfect, but it is a lot better than not testing them
Cedric Dugas