QUnit使用Ajax,QUnit通过了测试失败 [英] QUnit with Ajax, QUnit passes the failing tests
本文介绍了QUnit使用Ajax,QUnit通过了测试失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我期待到QUnit对JavaScript单元测试。我是在一个陌生的情况下,我核对从Ajax调用返回的值。
对于下面的测试,我故意想失败了。
//测试来检查的人都回来了!
测试(getPersons,函数(){
getPersons(函数(响应){
//人= $ .evalJSON(response.d);
等于(嘘,富,这个名字是有效的);
});
});
但它最终通过所有的时间。这里是getPersons方法,使Ajax调用。
函数getPersons(回调){
变种人= NULL;
$阿贾克斯({
键入:POST,
数据类型:JSON,
数据: {},
的contentType:应用/ JSON
网址:AjaxService.asmx / GetPersons
成功:函数(响应){
回调(响应);
}
});
}
解决方案
启动和使用QUnit库似乎是工作停止!
//测试来检查的人都回来了!
测试(getPersons,函数(){
停止();
getPersons(函数(响应){
人= $ .evalJSON(response.d);
等于(人[0] .FirstName,穆罕默德);
开始();
});
});
I am looking into QUnit for JavaScript unit testing. I am in a strange situation where I am checking against the value returned from the Ajax call.
For the following test I am purposely trying to fail it.
// 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");
});
});
But it ends up passing all the time. Here is the getPersons method that make the Ajax call.
function getPersons(callback) {
var persons = null;
$.ajax({
type: "POST",
dataType: "json",
data: {},
contentType: "application/json",
url: "AjaxService.asmx/GetPersons",
success: function(response) {
callback(response);
}
});
}
解决方案
Starting and stopping using the QUnit library seems to be working!
// test to check if the persons are returned!
test("getPersons", function() {
stop();
getPersons(function(response) {
persons = $.evalJSON(response.d);
equals(persons[0].FirstName, "Mohammad");
start();
});
});
这篇关于QUnit使用Ajax,QUnit通过了测试失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文