我需要用jasmine做一个真正的ajax请求的测试,
到目前为止,我有这样的想法:
function login(){
$.ajax({
method: 'GET',
url: url,
dataType: "json",
contentType: "application/json; charset=utf-8"
});
}
我需要获取登录成功响应,但为了实现这一点,jasmine需要等待请求结束,然后才能通过“its”迭代。我该怎么做呢?
发布于 2014-09-03 23:44:07
您需要使用"done()“,然后在您的异步请求完成后调用它。它是jasmine测试套件的一部分。所以就像这样。
function(done){
$.ajax({
method: 'GET',
url: url,
dataType: "json",
contentType: "application/json; charset=utf-8"
});
done();
}
发布于 2017-07-08 01:42:05
是不是应该更像是
function(done){
$.ajax({
method: 'GET',
url: url,
dataType: "json",
contentType: "application/json; charset=utf-8"
})
.then(done);
}
或替换为实际检查
.then(function(response){
//do your asserts here
done();
});
https://stackoverflow.com/questions/22818299
复制相似问题