title: Mock factory on controller test
body: <p>this is <strong>my controller</strong>:</p>
  
  <pre><code>angular
  .module('studentsApp')
  .controller('StudentsController', StudentsController);
  
  function StudentsController($scope, StudentsFactory) {
      $scope.students = [];
      $scope.specificStudent= {};
  
      var getStudents = function() {
          StudentsFactory.getStudents().then(function(response) {
              if($scope.students.length &gt; 0){
                  $scope.students = [];
              }
              $scope.students.push(response.data);
          });
      };
  }
  </code></pre>
  
  <p>This is <strong>my factory</strong>:</p>
  
  <pre><code>angular.module('studentsApp')
  .factory('StudentsFactory', function($http) {
    var base_url = 'http://localhost:3000';
    var studentsURI = '/students';
    var studentURI = '/student';
    var config = {
      headers: {
        'Content-Type': 'application/json'
      }
    };
  
    return {
      getStudents: function() {
        return $http.get(base_url + studentsURI);
      }
    };
  });
  </code></pre>
  
  <p>And here is how <strong>I'm trying to unit test the controller</strong>:</p>
  
  <pre><code>describe('Controller: Students', function() {
    var StudentsController, scope, StudentsFactory;
    beforeEach(function() {
      module('studentsApp');
      inject(function($rootScope, $controller, $httpBackend, $injector) {
        scope = $rootScope.$new();
        httpBackend = $injector.get('$httpBackend');
        StudentsFactory = $injector.get('StudentsFactory');
  
        StudentsController = $controller('StudentsController', {
          $scope : scope,
          'StudentsFactory' : StudentsFactory
        });
  
        students = [{
          name: 'Pedro',
          age: 10
        }, {
          name: 'João',
          age: 11
        }, {
          name: 'Thiago',
          age: 9
        }];
  
        spyOn(StudentsFactory, 'getStudents').and.returnValue(students);
      });
    });
  
    it('Should get all students', function() {
      scope.students = [];
  
      StudentsController.getStudents();
      $scope.$apply();
      expect(scope.students.length).toBe(3);
    });
  });
  </code></pre>
  
  <p><strong>The problem is</strong> when I run the test, the following message is displayed:</p>
  
  <blockquote>
    <p>undefined is not a constructor (evaluating
    'StudentsController.getStudents()')</p>
  </blockquote>
  
  <p>I looked at the whole internet trying to find a tutorial that can help me on that, but I didn't find anything, could someone help me here?</p>