views:

43

answers:

2

I could spike this to find out, but I'm going to use SO. In my unit tests (qunit) I use the asynchShould (alias for asynchTest) test. Part of the assertion is to wait for the completion/success of the request. Like this:

asyncShould('talk to customer list server', 1, function() {
    stop(2000);
    var forCustomerList = newCustomerListRequest();

    forCustomerList.page = 'helpers/helper.php';
    forCustomerList.data += '&action=customerListServer&DB=11001';
    var originalSuccess = forCustomerList.success;

    forCustomerList.success = function(msg) {
        if (msg.flash !== undefined && msg.data !== undefined && msg.status !== undefined) {
            ok(true, 'json structure correct')
        }
        else {
            ok(false, 'json structure not correct');
        }
        originalSuccess(msg);
        start();
    };

    testController.getServerData(forCustomerList);
})
+4  A: 

"complete" fires after "success" or "failure"

zed_0xff
+5  A: 

From the jQuery site http://api.jquery.com/jQuery.ajax/

complete(XMLHttpRequest, textStatus)Function

A function to be called when the request finishes (after success and error callbacks are executed)...

aSeptik
I don't remember how many times I've read that page and didn't see it.
Gutzofter