3

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

1 Answer 1

1

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();
Sign up to request clarification or add additional context in comments.

1 Comment

this is not perfect, but it is a lot better than not testing them

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.