title: How to test that an angular factory function using a promise is throwing an error in jasmine
body: <p>Here's how my function looks like.</p>
  
  <pre><code>var myFunc = function(){
     return functionReturningaPromise()
            .then(function(){
                //success, doesn't matter what happens here
            })
            .catch(function(err){
                //handle error here and then throw to handle higher
                throw new Error('Error in my function');
            })
  }
  </code></pre>
  
  <p>I need the function to be this way to handle an error inside this function and then throw an error to handle on higher level. But i don't know how to test it with jasmine. I know how to control the promises for testing and my basic set up looks like this:</p>
  
  <pre><code>it('Should throw an error', inject(function(alert) {
      var instance = instanceFactory.createInstance(someData);
      var deferred = $q.defer();
      spyOn(someFactory, 'someMethod').and.returnValue(deferred.promise);
  
      //instance contains the throwing function above 
  
      instance.myFunc(otherData);
  
      deferred.reject({data: '12 - error'});
      $rootScope.$digest();
  
      expect(instance.myFunc).toThrow();
  
  }));
  </code></pre>
  
  <p>Obviously, the error is not found by jasmine. So how to test the error throw in this case</p>