title: Test AngularJS factory function with Jasmine
body: <p>I am very new to this (angularjs, jasmine, testacular) and I have this code (I simplified it a bit, leaving only what matters):</p>
  
  <pre><code>//my_module.js
  angular.module('my_module', ['my_data'])
  .config([...]);
  
  .controller('my_controller', ['$scope', 'my_data',
      function($scope, my_data) {
          $scope.my_function = function() {
              return my_data.my_factory.save().then(function () {
                  console.log('saved');
              },
              function() {                             
                  console.log('Error');
              }); 
          }
      }
  )
  
  //my_data.js
  angular.module('my_data', [])
  .factory('my_factory', ['$q', '$rootScope',
      function($q, $rootScope) {
          var my_factory= function(my_data) {
              angular.extend(this, my_data);
          }
          my_factory.prototype.save = function() {
              var deferred = $q.defer();
              setTimeout(function() {
                  deferred.resolve();
              $rootScope.$apply();
              }, 1000);
  
              return deferred.promise;
          }
          return my_factory;
      }
  ])
  </code></pre>
  
  <p>So, what I want to do is to test if my_data.my_factory.save is called when the my_module.my_controller.my_function is fired. </p>
  
  <pre><code>//my_test.js
  describe('testing my_controller.my_function', function () {
      beforeEach(module('my_module'));
  
      var $rootScope, $controller;
      beforeEach(inject(function(_$rootScope_, _$controller_) {
          $rootScope = _$rootScope_;
          $controller = _$controller_;
      }));
  
      scope = $rootScope.$new();
  
      it('should call the save function', function() {
          scope.my_function();
          expect(my_data.save).toHaveBeenCalled();
      });
  }
  </code></pre>
  
  <p>I need a little bit of help.</p>