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: [email protected]
[mailto:[email protected]] 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
_______________________________________________________
fluid-work mailing list - [email protected]
To unsubscribe, change settings or access archives,
see http://fluidproject.org/mailman/listinfo/fluid-work