title: how to unit test a ngcontroller with external dependencies in jasmine?
body: <p>I am trying to write a karma unit test for a angularcontroller, this is the controller. Using a fileupload from here (<a href="https://github.com/nervgh/angular-file-upload" rel="nofollow">https://github.com/nervgh/angular-file-upload</a>):</p>
  
  <pre><code>var c, di;
  
  c = function($scope, FileUploader, UploadHelper, currentUser) {
    var uploader;
  
    $scope.uploader = uploader = new FileUploader(UploadHelper.getOptions());
  
    uploader.onSuccessItem = function(item, response, status, headers) {
      //do something
    };
    return this;
  };
  
  di = [ '$scope', 'FileUploader', 'UploadHelper', 'currentUser', c];
  
  angular.module('mycontrollers').controller('DocumentsController', di);
  </code></pre>
  
  <p>My jasmine test looks like this:</p>
  
  <pre><code>describe('Customer: Controller: DocumentsController', function() {
    var $rootScope, DocumentMock, UserMock, documentsController, scope;
    documentsController = $rootScope = scope = DocumentMock = UserMock = null;
  
    beforeEach(function() {
      module("mycontrollers");
      return inject(function($controller, _$rootScope_, $q) {
        var deferred, documents, fileUploader, uploadHelper, user;
        $rootScope = _$rootScope_;
        scope = $rootScope.$new();
        documents = [
          {
            id: "doc 1",
            documentType: "other"
          }, {
            id: "doc 2",
            documentType: "pdf"
          }, {
            id: "doc 3",
            v: "pdf"
          }
        ];
        user = {
          id: 'user_id',
          username: 'username'
        };
        UserMock = {
          currentUser: function() {
            return user;
          }
        };
        fileUploader = {};
        uploadHelper = {};
  
        return documentsController = $controller('DocumentsController', {
          documents: documents,
          $scope: scope,
          FileUploader: fileUploader,
          UploadHelper: uploadHelper,
          currentUser: UserMock
  
        });
      });
    });
    return describe("On creation", function() {
      return it("should assign documents to scope", function() {
        return expect(1).toEqual(1);
      });
    });
  });
  </code></pre>
  
  <p>I got a service called QuestionsAttachments which has a few dependencies:</p>
  
  <pre><code>s = function(API, $http, $q, $timeout) {
    var QuestionsAttachments;
    return QuestionsAttachments = (function() {
      function QuestionsAttachments(data) {
        angular.extend(this, data);
      }
  
      QuestionsAttachments["new"] = function(data) {
        return new QuestionsAttachments(data);
      };
  
      return QuestionsAttachments;
  
    })();
  };
  
  di = ['API', '$http', '$q', '$timeout', s];
  </code></pre>
  
  <p>This questions is: how can I mock out the API ,$http, $q, $timeout ?</p>
  
  <p>This is a link to a plunkr:
  <a href="http://plnkr.co/edit/BT8SJgW6ejcPw6xo1cpI?p=preview" rel="nofollow">http://plnkr.co/edit/BT8SJgW6ejcPw6xo1cpI?p=preview</a></p>