title: Angularjs controller's $scope undefined whille unit testing and using Google Closure Library
body: <p>My question is quite simple but hard to answer... how to inject a $scope to an AngularJs controller under test using google closure tools.</p>
  
  <p>The controller is quite simple, basically it performs a http request to the server through the <code>_getOrganisations</code> function</p>
  
  <p><strong>Here is the actual controller:</strong></p>
  
  <pre><code>goog.provide 'MyModule.controllers.Menu'
  
  MyModule.controllers.Menu = ($scope, $http, $location, SomeService) -&gt;
    _getOrganisations = () -&gt;
  
      $http({SomeRequestOptions})
        .success(_handleGetOrganisationsSuccessCallback)
        .error(_handleGetOrganisationsErrorCallback)
  
    _handleGetOrganisationsSuccessCallback = (result, status) -&gt;
      $scope.organisations = result
  
    _handleGetOrganisationsErrorCallback = (err, status) -&gt;
      [...]
  
    $scope.toggleMenu = () -&gt;
      angular.element('.nav-collapse').collapse('toggle')
  
    _getOrganisations()
  </code></pre>
  
  <p><strong>Here is how I tried to test my controller</strong></p>
  
  <pre><code>describe 'menu controller', () =&gt;
  
      result=
          org1 : ''
          org2 : ''
          org3 : ''
  
      beforeEach () -&gt;
          goog.require 'MyModule.controllers.Menu'
  
          inject ($rootScope, $controller, $http, $httpBackend) -&gt;
              scope = $rootScope.$new()
              httpBackend = $httpBackend
              httpBackend.whenGET({SomeRequestOptions}).respond result
              menuController = $controller new MyModule.controllers.Menu(), {$scope : scope, $http : $http}
  
      it 'should get organisations properly', () -&gt;
          expect(scope.organisations).toEqual(result)
  </code></pre>
  
  <p>When I'm trying to assign my actual controller to the menuController, $scope is undefined... What am I missing here ?</p>