我可以赶上这个来找出来,但是我要用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); })
解决方法
从jQuery网站
http://api.jquery.com/jQuery.ajax/
complete(XMLHttpRequest,
textStatus)FunctionA function to be called when the request finishes (after success and error callbacks are executed)…