I have a problem making mocks with promises for a test with karma:
When I execute the "resolve (value)" of my promise, it does not jump to the then , does nothing, does not go to the "error", does not go to the "resolve" and the test is it remains in OK, (the objective of the test is simply to pass all the functionality without giving errors)
Here is the code that will be executed (I had to delete code but the problem is understood):
getLoadData() {
let vm = this,
url = ...;
let _search = {
...
};
return vm.httpCacheGett(url,_search).then(getDataComplete, getDataFailed);
function getDataComplete ( res ) : Object {
console.log(7)
return "todo ok"
}
function getDataFailed( err : any ) : Object {
return "todo mal"
}
}
Here is the test code:
it('con error ', () => {
linesDashboardServ.httpCacheGett = function(a,c){
console.log(2);
var defered = $q.defer();
var promise = defered.promise;
setTimeout(function(){
console.log(3);
defered.resolve([{1:1}]);
}, 1);
return promise;
};
linesDashboardServ.getLoadData("1");
});
What I do not understand is because it does not fit into the "console.log (7)" because it shows it to me in "console.log (3), so I should run the resolve ()
Do you know what it can be?