0

Suppose I have a function

function f_createScriptElement(f_url) {
        var script = d[CreateElement](Script);
        script.type = "text/javascript";
        script[Src] = f_url;
        script.async = true;

        try {
            var container = ((m_videoPlayerTagId) ? d[GetElementById](m_videoPlayerTagId) : f_getAdContainerElem());
            if (container) {
                container.addEventListener("loadedmetadata", function(e) {
                    var c_width = this.videoWidth,
                        c_height = this.videoHeight,
                        v_width = this[WIDTH],
                        v_height = this[HEIGHT];

                    m_playerProperties[NS_AD_CD] = container.duration;
                    m_playerProperties[NS_AD_SZ] = c_width + "x" + c_height;
                    m_playerProperties[NS_AD_PS] = v_width + "x" + v_height;
                    m_playerProperties[NS_AD_VS] = ((container.volume === 0) ? false : true);

                }, false);

                container.parentNode.insertBefore(script, container.nextSibling);
            } else {
                return;
            }
        } catch (err) {}
    }

It would be great if you could tell the appropriate test cases you would write(Both Positive and Negative) to have complete code coverage for this function in QUnit since it doesnt return a string or a number.

1 Answer 1

1

As this is a function with a side effect you have to test the side effect, which is the inserting of the script element into the DOM. To test the positive case, add a DOM element, which will make the if(container) statement pass and check that the script tag with right attributes was added to the DOM. For the negative just run the test and check that the script element is missing in the DOM.

Sign up to request clarification or add additional context in comments.

1 Comment

Koberle May be I can insert my test cases written in Qunit into the test page html so that I can have access over the DOM.Thanks for ur answer.

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.