title: TypeError: undefined is not a function Angularjs
body: <p>I've a unit tests that's keep failing with the error above not sure what exactly is wrong with this, by the looks of the error, its says that I need to declare a function. Can someone point me what is wrong with my code please:</p>
  
  <h2>unit test</h2>
  
  <pre><code>describe('Test loginService', function() {
  var $location, loginService, $scope, authentication, $rootScope;
  beforeEach(function() {
      module('app');
      inject(function(_$location_, _$rootScope_, _loginService_,
              _authentication_) {
          $location = _$location_;
          authentication = _authentication_;
          loginService = _loginService_;
          $rootScope = _$rootScope_;
          $scope = $rootScope.$new();
      });
  });
  
  it('Should successfully login with correct credentials', function() {
      $scope.username = 'a@a.com';
      $scope.password = 'a';
      spyOn($location, 'url');
      loginService.login($scope);//Complains about this line
  
      expect($location.url).toHaveBeenCalled();
      expect($location.url).toHaveBeenCalledWith('/home');
  });
  </code></pre>
  
  <h2>login service</h2>
  
  <pre><code>app.factory('loginService', function(parserService, $location,
      authentication, $rootScope) {
  return {
      login : function(scope) {
          parserService.getData().then(function(data) { //This line 
              if (scope.username === data.username
                      &amp;&amp; scope.password === data.password) {
                  ...
                  $location.url("/home");
              } else {
                  scope.loginError = "Invalid Credentials";
              }
          });
      }
  });
  </code></pre>
  
  <h2>Json file reader service</h2>
  
  <pre><code>app.factory('parserService', function($http, $q) {
  return {
      getData: function() {
             var deferred = $q.defer();
             $http.get('res/file.json').success(function(data) {
                deferred.resolve(data);
             }).error(function(){
                deferred.reject();
             });
             return deferred.promise;
       }
  }
  });
  </code></pre>
  
  <h2>error log</h2>
  
  <pre><code>Chrome 36.0.1985 (Windows 7) Test loginService Should successfully login with correct credentials FAILED
  TypeError: undefined is not a function
          at Object.login     (D:../js/services/loginService.js:6:18)
          at null.&lt;anonymous&gt; (D:/../test/unit/loginTest.js:92:16)
  </code></pre>