FW: Fetching templates in tests using jqUnit

Jacob Farber jacob.farber at utoronto.ca
Tue Jul 21 19:36:48 UTC 2009


We've also found that you can use stop() anywhere before the async stuff fires, so
function setup () {
            stop();
            foo();
            var ajaxCallback = function () {
                        blah();
                        var secondAjaxCallback = function ()
                                    start();
                        }
                        ajax(secondAjaxCallback);
            };
            ajax(ajaxCallback);
            bar();
}

Could look like
function setup () {
            foo();
            var ajaxCallback = function () {
                        blah();
                        var secondAjaxCallback = function ()
                                    start();
                        }
                        ajax(secondAjaxCallback);
            };
            stop();
            ajax(ajaxCallback);
            bar();
}

...if this helps make code flow clearer. So, to reiterate what Michelle said previously, all of setup() will fire, the results will be stored, ajaxCallback() will fire whenever its supposed to and its results will also be stored, and then secondAjaxCallback() will fire - once this last callback fires, the test will move on to the next phase and evaluate the tests results that it has been storing all at once.



From: fluid-work-bounces at fluidproject.org [mailto:fluid-work-bounces at fluidproject.org] On Behalf Of Michelle D'Souza
Sent: Thursday, July 16, 2009 5:03 PM
To: fluid-work List
Subject: Re: Fetching templates in tests using jqUnit


If you look at the code for 'fetchTemplate' you'll notice the use of 'stop' and 'start'. These are QUnit functions that pause the test runner while waiting for the AJAX response. The way to use them is to call 'stop' prior to your ajax call and call 'start' in the ajax callback.

Thought I'd give a little more information on using 'stop' and 'start'. There are 4 lifecycle phases in the test: setup, testbody, teardown, reset. If stop is called in one of the lifecycle phases, that lifecycle phase continues until it is done but the next lifecycle phase will not begin until 'start' has been called. In the following example foo and bar will be run before the ajax call returns but baz will only run after the 'start' call in the ajax callback.

function setup () {
            stop();
            foo();
            var ajaxCallback = function () {
                        start();
            };
            ajax(ajaxCallback);
            bar();
}

function testBody () {
            baz();
}

The implication here is that if you want to run some tests after the ajax call has returned, you need to put those tests into the callback. If you want to do another ajax call after running those tests, you need to put the ajax call into the callback also like this:

function setup () {
            stop();
            foo();
            var ajaxCallback = function () {
                        blah();
                        var secondAjaxCallback = function ()
                                    start();
                        }
                        ajax(secondAjaxCallback);
            };
            ajax(ajaxCallback);
            bar();
}

function testBody () {
            baz();
}

In the second example, foo and bar run before any ajax calls return. 'blah' runs after the first ajax call and 'baz' runs after the second (nested) ajax call.

Hope this helps.

Michelle

------------------------------------------------------
Michelle D'Souza
Software Developer, Fluid Project
Adaptive Technology Resource Centre
University of Toronto



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.idrc.ocad.ca/pipermail/fluid-work/attachments/20090721/7ac8ddee/attachment.htm>


More information about the fluid-work mailing list