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.

Swaraj Chhatre
  • 627
  • 1
  • 10
  • 22

1 Answers1

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.

Andreas Köberle
  • 106,652
  • 57
  • 273
  • 297
  • 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. – Swaraj Chhatre Oct 04 '13 at 20:49