title: Having problems unit testing a promise call in angularjs controller
body: <p><code>SupportedLanguagesServices</code> get method returns a <code>promise</code> which is resolved in the controller as follows:</p>
  
  <pre><code>    angular.module('App').controller('MyController', ['SupportedLanguagesService',
      function(SupportedLanguagesService) {
  
          var self = this;
          self.supportedLanguages = [];
  
          SupportedLanguagesService.get().success(
              function(response) {
                  self.supportedLanguages = response;
          });
  
      }]);
  </code></pre>
  
  <p>And here is the test I wrote, but it is not working:</p>
  
  <pre><code>    describe('Controller: MyController', function() {
  
      beforeEach(module('App'));
  
      var rootScope, controller;
  
      beforeEach(inject(function($controller, $rootScope, SupportedLanguagesService, $q) {
  
          var deferred = $q.defer();
          deferred.resolve([{name:"English", code:"en"},{name:"Portugues", code:"pt_BR"]);
          spyOn(SupportedLanguagesService, 'get').andReturn(deferred.promise);
  
          rootScope = $rootScope;
          controller = $controller;
      }));
  
      it('should get SupportedLanguages', function() {
          rootScope.$digest();
          var ctrl = controller('MyController');
          expect(ctrl.supportedLanguages.length).toEqual(2);
      });
  
  });
  </code></pre>
  
  <p>It throws an exception on the statement: <code>var ctrl = controller('MyController');</code></p>
  
  <p>Thank you for your assistance.</p>