[英]how can I test this async function over jasmine
my function in the service is 我在服务中的职能是
listo: function () {
var deferred = $q.defer();
setTimeout(function () {
deferred.resolve(true);
}, 2000);
return deferred.promise;
}
in jasmine test I have 在茉莉花测试中
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();
});
});
I got the following error: 我收到以下错误:
Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. 错误:超时-jasmine.DEFAULT_TIMEOUT_INTERVAL指定的超时内未调用异步回调。
PhantomJS 2.1.1 (Linux 0.0.0) testeando local storage should support async execution of test preparation and expectations FAILED Expected undefined to be true. PhantomJS 2.1.1(Linux 0.0.0)testeando本地存储应支持测试准备和期望的异步执行FAILED期望undefined为真。
Try to set delay parameter for that test to be more than 2000 ms: 尝试将该测试的延迟参数设置为大于2000毫秒:
it("prueba",function(done){
bd.listo().then(function(res) {
valor = res;
done();
})
}, 3000);
Also you may try to do it for whole the spec: 您也可以尝试在整个规范中做到这一点:
beforeEach(function() {
jasmine.DEFAULT_TIMEOUT_INTERVAL = 3000;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.