[英]how can I test this async function over jasmine
我在服務中的職能是
listo: function () {
var deferred = $q.defer();
setTimeout(function () {
deferred.resolve(true);
}, 2000);
return deferred.promise;
}
在茉莉花測試中
describe("testeando local storage", function () {
var bd;
beforeEach(module('modulo'));
beforeEach(inject(function (bds) {
bd = bds;
}));
beforeEach(function () {
expect(bd).toBeDefined();
});
var valor;
it("prueba",function(done){
bd.listo().then(function(res) {
valor = res;
done();
})
});
it("pruebita", function(done) {
expect(valor).toBe(true);
done();
});
});
我收到以下錯誤:
錯誤:超時-jasmine.DEFAULT_TIMEOUT_INTERVAL指定的超時內未調用異步回調。
PhantomJS 2.1.1(Linux 0.0.0)testeando本地存儲應支持測試准備和期望的異步執行FAILED期望undefined為真。
嘗試將該測試的延遲參數設置為大於2000毫秒:
it("prueba",function(done){
bd.listo().then(function(res) {
valor = res;
done();
})
}, 3000);
您也可以嘗試在整個規范中做到這一點:
beforeEach(function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 3000;
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.