title: AngularJS Karma Jasmine Error: Cannot Read Property of Undefined
body: <p>This is my first attempt at using Karma/Jasmine. I want to use it to test an AngularJS app.</p>
  
  <p>This is just a simple Hello World test to make sure things are working but they are not.</p>
  
  <p>I am trying to test a controller called InboxController. I have defined a scope variable: $scope.greeting = 'Hello World'.</p>
  
  <p>I am trying to test that in a separate file called controllers-test.js.</p>
  
  <p>This is the test:</p>
  
  <pre><code>'use strict';
  </code></pre>
  
  <p>describe('Controllers Tests ', function () {</p>
  
  <pre><code>describe('InboxController', function () {
      var scope;
  
      beforeEach(angular.mock.module('myApp'));
  
      beforeEach(angular.mock.inject(function($rootScope, $controller){
          scope = $rootScope.$new();
          $controller('InboxController', {$scope: scope});
  
      }));
  
      it('should return Hello World', function () {
          expect(scope.greeting).toBe('Hello World');
      });
  });
  </code></pre>
  
  <p>});</p>
  
  <p>I keep getting an error:</p>
  
  <p>Cannot read property 'greeting' of undefined, which relates back to scope.greeting in the test code.</p>
  
  <p>Karma config:</p>
  
  <pre><code>files : [
  
              'bower_components/angular/angular.js',
              'bower_components/angular-mocks/angular-mocks.js',
              'bower_components/angular-resource/angular-resource.js',
              'app.js',
              'js/*.js',
              'test/*.js'
               ],
  </code></pre>
  
  <p>InboxController:</p>
  
  <pre><code>app.controller('InboxController', function($rootScope, $scope,
      $location, InboxService) {
  
  $scope.greeting = 'Hello World';
  
  $rootScope.loggedIn = true;
  
  // Load Inbox
  $scope.loadInbox = function() {
  
      $scope.emails = InboxService.getMessages().success(function(jsonData) {
  
          $scope.emails = jsonData;
      });
  }
  
  // Delete email
  $scope.delete = function (id) {
      InboxService.delete(id).success(function() {
  
          $scope.loadInbox();
      });
  };
  
  $scope.loadInbox();
  </code></pre>
  
  <p>});</p>