I would like if someone can help me to test this function without using the setTimeout I am using in the TEST FILE. after investigating a lot I could make it walk, but that setTimeout is a time bomb. probe with jasmine-promises and in a thousand different ways but none of them worked for me
service:
angular.module('moduloPrueba', [])
.factory('asincronico', function($q) {
return {
tes:tes,
};
function tes(){
var deferred = $q.defer();
setTimeout(function () {
deferred.resolve(79);
}, 50);
// Return the deferred promise
return deferred.promise;
}
});
jasmine test:
describe('description', function () {
var asi;
var root;
var res;
beforeEach(function () {
module('moduloPrueba');
inject(function (asincronico, $rootScope) {
root = $rootScope;
asi = asincronico;
})
});
it('should ', function (done) {
asi.tes().then(function (resp) {
res = resp;
done();
});
setTimeout(function () {
root.$digest();
expect(res).toEqual(79);
expect(res).not.toEqual(123);
}, 200);
});
});