I'm trying to get chai-as-promised
to work with $q
promises with karma unit tests.
svc.test = function(foo){
if (!foo){
// return Promise.reject(new Error('foo is required'));
return $q.reject(new Error('foo is required'));
} else {
// get data via ajax here
return $q.resolve({});
}
};
it.only('should error on no foo', function(){
var resolvedValue = MyServices.test();
$rootScope.$apply();
return resolvedValue.should.eventually.be.rejectedWith(TypeError, 'foo is required');
});
The unit test just times out. I am not sure what I'm doing wrong here to get the promise to resolve properly. It seems to be an issue with using $q
-- when I use native Promise.reject()
it works fine.
I filed a ticket here, but nobody seems to be responding: https://github.com/domenic/chai-as-promised/issues/150
See Question&Answers more detail:os