我可以通过这个来找出答案,但我打算使用它。在我的单元测试(qunit)中,我使用asynchShould(别名asynchTest)测试。部分断言是等待请求的完成/成功。就像这样:Ajax请求。哪个回调首先执行完成或成功?
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);
})