有人可以告诉我我们是否需要使用 asyncTest() 来测试同步 ajax 调用,或者 test() 可以在没有 start() 和 stop() 的情况下使用。
考虑一下:
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
};
} ();
当"异步"属性为"真"和"假"时,我们如何为 Class.Students() 方法编写测试用例?
与 asyncTest 和 asnyc 真或假:
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 异步处理
使用不启动或停止的测试可能会使测试失败