[英]QUnit testing synchronous ajax calls
有人可以告诉我我们是否需要使用asyncTest()测试同步ajax调用,或者可以在没有start()和stop()的情况下使用test()。
考虑一下:
var Class= function () {
var init = function () {
amplify.request.define('students', 'ajax', {
url: '/methods/GetStudentsList',
dataType: 'json',
type: 'GET',
async:false
});
};
Students = function (branch, callback) {
init();
return amplify.request("students",
{ branchID: branch },
callback.success,
callback.error
);
};
return {
Students: Students
};
} ();
当'async'属性为'true'和'false'时,我们如何编写Class.Students()方法的测试用例?
带有asyncTest和asnyc的true或false:
asyncTest("test", function () {
init.Students(someBranch, function (a, b, c) {
ok(true); //add your tests here
start();
});
});
与测试和停止/启动:
test("test", function () {
stop();
init.Students(someBranch, function (a, b, c) {
ok(true); //add your tests here
start();
});
});
请注意,两种情况下qunit都会异步处理您的请求
使用没有开始或停止的测试可能会使您的测试失败
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.