title: How do I test variables local to an Angular controller in Jasmine
body: <p>I have a controller with a local variable</p>
  
  <pre><code>function IndexCtrl($scope) {
    var pagesById = [];
    loadPages();
  
    // snip
  
    function loadPages() {
      // pagesById gets populated
    }
  
    // snip
  }
  </code></pre>
  
  <p>I'd like to test that pagesById is correctly populated but I'm not sure how to get at it from my it(). I don't need this variable to be in the $scope, it's just an intermediate set of information, so if I can avoid adding it to $scope that would be ideal.</p>
  
  <pre><code>it('scope.pages should populated based on pages data.', function() {
      $httpBackend.flush();
      expect(pagesById).toEqualData(mock_page_results);
  });
  </code></pre>
  
  <p>gives me</p>
  
  <pre><code>ReferenceError: pagesById is not defined
  </code></pre>
  
  <p>Do I have any other options besides attaching it to $scope?</p>