我可能会发现这一点,但我会使用SO。在我的单元测试(qunit)中,我使用asynchShould
(asynchTest的别名)测试。部分断言是等待请求的完成/成功。像这样:
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);
})
答案 0 :(得分:11)
<强>成功强>
来自jQuery网站http://api.jquery.com/jQuery.ajax/
<强>完成(XMLHttpRequest的, textStatus)功能
一个功能 请求完成时调用 (在成功和错误回调之后 执行)...
答案 1 :(得分:6)
“完成”在“成功”或“失败”之后开火