vendredi 27 mars 2015

How do you resolve a $q.reject promise from a then block in unit testing?

Here is my test, but I'm having the problem that neither my success nor reject functions are being hit. If I resolve the Http promise with good data, then my success function is hit (which then throws the exception "this should not be hit"). I'm expecting the error handler to be hit when bad data does in, but it never does. What am I doing wrong?



it("should resolve to failure action", function(done){
Service.load().then(function(){
throw new Exception("This should not be hit");
}, function(){
done();
});

$http.post.resolve(badData);
});


// mean while, the Service.load function
load: function(){
return this.getHttpPromise().then(function(data){
// process our data
if(data.isGood)
return data;

return $q.reject("Data is not good");
});
}

Aucun commentaire:

Enregistrer un commentaire