Los Techies : Blogs about software and anything tech!

Asynchronous JavaScript Testing with QUnit


I’m implementing a feature that does some stuff when an IFRAME is finished loading.  Due to the inherent asynchronous nature of this functionality, it was hard to test.  I was trying to use QUnit, but having issues, until I found this post:

http://markdotmeyer.blogspot.com/2008/07/javascript-unit-testing-with-qunit.html

The summary?  Check out the stop() and start() functions.

Now, I can write my test like this:

test("addWindow should remove the loadingStauts div after the iframe is loaded", function() {
    
    var loadingStatus = $("<div></div>").attr("id", "loadingDiv");
    
    var stack = $("<div></div>")
                    .attr("id", "stackDiv")
                    .appendTo("#stack")
                    .windowStack()
                    .withLoadingStatus(loadingStatus);

    stack[0].addWindow("Blank_for_iframe_testing.htm", "");

    stop();

    setTimeout(function() {
        equals(loadingStatus[0].parentNode, null, "loadingStatus DIV should be removed after the iframe is loaded");
        start();
    }, 500);
});
Kick It on DotNetKicks.com
Posted Dec 22 2008, 01:24 PM by chadmyers
Filed under:

Comments

Dew Drop - December 23, 2008 | Alvin Ashcraft's Morning Dew wrote Dew Drop - December 23, 2008 | Alvin Ashcraft's Morning Dew
on 12-23-2008 4:34 PM

Pingback from  Dew Drop - December 23, 2008 | Alvin Ashcraft's Morning Dew

John Teague's Blog wrote Another Way to Test Ajax Methods
on 02-10-2009 12:47 AM

A while ago, Chad posted about how to test Ajax methods with QUnit .  I’m also testing Ajax calls

Copyright Los Techies 2008, 2009. All rights reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems