title: AngluarJS Unit Test - Undefined is not a function
body: <p>I am trying to learn how to unit test within angular. Unit testing my controllers to start with then my services.</p>
  
  <p>I have started off with a basic test.</p>
  
  <p>Controller code:</p>
  
  <pre><code>angular.module('app')
    .controller('TestCtrl', function ($rootScope,$scope,fileLoader,ngProgress) {
   $scope.test= [];
      $scope.init = function(){
        fileLoader.getFile("test")
          .then(function(res){
            //Success
            console.log(res);
            $scope.test= res;
          }, function(err){
            //Error
          });
  
        ngProgress.complete();
      }
  
      $scope.init();
  $scope.title = "Test";
    });
  </code></pre>
  
  <p>Test code:</p>
  
  <pre><code>describe('Controller: TestCtrl', function () {
  
    // load the controller's module
    beforeEach(module('app'));
  
    var TestCtrl,
      scope,test;
    test = {};
    test.getFile = function(name) {
      return [
        {
          "id": 0,
          "name": "Test",
          "imgName": "Test.png"
        },
        {
          "id": 1,
          "name": "Test1",
          "imgName": "Test1.png"
        }];
    };
  
  
    // Initialize the controller and a mock scope
    beforeEach(inject(function ($controller, $rootScope) {
      scope = $rootScope.$new();
      TestCtrl= $controller('TestCtrl', {
        $scope: scope,
        fileLoader : test
      });
    }));
  
    it('should have the correct title', function () {
      expect(scope.title).toBe("Test");
    });
  });
  </code></pre>
  
  <p>And I can't understand why I am getting the following error:</p>
  
  <blockquote>
    <p>TypeError: 'undefined' is not a function (evaluating
    'fileLoader.getFile("test")
              .then')     undefined</p>
  </blockquote>
  
  <p>Is there any way once this is resolved I can lay all my mocking out in a separate file e.g. my fileLoader mock and just inject it that way?</p>
  
  <p>I don't understand how I am injecting it but yet it is undefined.</p>
  
  <p>Thanks</p>