我正在研究QUnit for JavaScript单元测试.我在一个奇怪的情况下,我正在检查从Ajax调用返回的值.
对于以下测试,我故意试图让它失败.
// test to check if the persons are returned!
test("getPersons", function() {
getPersons(function(response) {
// persons = $.evalJSON(response.d);
equals("boo", "Foo", "The name is valid");
});
});
Run Code Online (Sandbox Code Playgroud)
但它最终总是在传递.这是进行Ajax调用的getPersons方法.
function getPersons(callback) {
var persons = null;
$.ajax({
type: "POST",
dataType: "json",
data: {},
contentType: "application/json",
url: "AjaxService.asmx/GetPersons",
success: function(response) {
callback(response);
}
});
}
Run Code Online (Sandbox Code Playgroud)