Is it possible to resolve an angular promise immediately and effectively have the code behave like a synchronous call? I know this defeats the purpose of promises, but I want to do this for unit testing purposes. My testing shows that the then is called right away, but I am not sure if there is a potential timing issue here where the then
is still considered asynch?
function someService(){
var deferred = $q.defer();
deferred.resolve(myObj);
return deferred.promise;
}
someService().then(function(obj){
//will this be executed right away just like it would if this was a synchronous call?
// more code here under test
});
var myVal = 10;
Will the myVal assignment be executed before the then callback? Or can I trust that the then will always go right away?