【发布时间】:2018-01-18 05:21:22
【问题描述】:
我结识了 Jasmine (http://pivotal.github.com/jasmine/),发现了一些相当莫名其妙的事情:
it("should be able to send a Ghost Request", function() {
var api = fm.api_wrapper;
api.sendGhostRequest(function(response) {
console.dir('server says: ', response);
});
expect(true).toEqual(false);
});
按预期失败。
但是,在回调中移动期望调用:
it("should be able to send a Ghost Request", function() {
var api = fm.api_wrapper;
api.sendGhostRequest(function(response) {
console.dir('server says: ', response);
expect(true).toEqual(false);
});
});
不知何故通过 :O
经过一些调试: api.sendGhostRequest() 做一个异步ajax请求,在请求完成之前jasmine就冲过去了。
因此问题:
如何让 jasmine 在确定测试结果之前等待 ajax 执行?
【问题讨论】:
-
使用 Jasmine 2.0,您只需调用它("desc",function(done){... done(); ...})。只是说,因为这个线程在谷歌结果中很高:)
标签: javascript ajax bdd jasmine