I have a test I want to do before I make an ajax call. If that test is a failure condition I want to immediately reject, but it seems I cannot do that:
  svc.test = function(foo){
    var def = $q.defer();
    if (!foo){
      def.reject(new Error('failed'));
    } else {
      // get data via ajax here
      def.resolve({})
    }
    return def.promise;
  };
I tried adding setTimeout around the def.reject() but then my unit test doesn't work.
  it.only('should error ', function(){
    return expect(MyServices.test()).to.eventually.be.rejectedWith('failed');
  });
Using native promise works fine, but I need to do this with $q:
  return Promise.reject(new Error('failed'));
 
    