title: AngularJS Controller Unit Testing
body: <p>I new in AngularJS and try Unit Testing.I am using Karma and Jasmine. I created the first test for my controller but its not working and I don't know why karma throughs an error.</p>
  
  <p>So please help me out this.</p>
  
  <p><strong>BasicTabCtrl.js</strong></p>
  
  <pre><code>// Basic Tab Controller 
  myApp.controller('BasicTabCrtl', ['$scope', '$modal', 'BasicTabService', function ($scope, $modal, BasicTabService) {
      console.log("BAsic tab crtl");
  
      $scope.name = 'testing';
      $scope.tab1 = "BASIC";
      $scope.tab2 = "ADVANCE";
      $scope.tab3 = "FORM";
  
      $scope.user = {};
      // get user from service
      $scope.Tablelist = BasicTabService.getUser();
  
      // delete user
      $scope.deleteUser = function (obj) {
          console.log("OBJ =&gt; " + JSON.stringify(obj));
          if (obj != -1) {
              $scope.Tablelist.splice(obj, 1);
          }
      }
  }]);
  </code></pre>
  
  <p>Here is my test case</p>
  
  <p><strong>example.js</strong></p>
  
  <pre><code>describe('myApp',function(){
   var scope,controller;
  
   beforeEach(function(){
      module('myApp');
   });
  
    describe('BasicTabCrtl',function(){
  
      beforeEach(inject(function($rootScope,$controller){
          scope = $rootScope.$new();
          controller=$controller('BasicTabCrtl',{
              '$scope':scope
          });
          console.log("d");
      }));
  
      it('set the name',function(){
          expect(scope.name).toBe('testing');
      });
  
    });
  
  });
  </code></pre>
  
  <p><strong>Error</strong></p>
  
  <pre><code>26 05 2016 20:47:50.890:INFO [watcher]: Changed file "/home/rahul/Documents/django_project/myfirstsite/test/example.js".
  Firefox 46.0.0 (Ubuntu 0.0.0) myApp BasicTabCrtl set the tab1 name FAILED
      minErr/&lt;@/home/rahul/Documents/django_project/myfirstsite/static/js/angular.js:68:12
      loadModules/&lt;@/home/rahul/Documents/django_project/myfirstsite/static/js/angular.js:4587:15
      forEach@/home/rahul/Documents/django_project/myfirstsite/static/js/angular.js:322:11
      loadModules@/home/rahul/Documents/django_project/myfirstsite/static/js/angular.js:4548:5
      createInjector@/home/rahul/Documents/django_project/myfirstsite/static/js/angular.js:4470:19
      workFn@/home/rahul/Documents/django_project/myfirstsite/static/js/angular-mocks.js:2954:44
      TypeError: scope is undefined in /home/rahul/Documents/django_project/myfirstsite/test/example.js (line 19)
      @/home/rahul/Documents/django_project/myfirstsite/test/example.js:19:3
  Firefox 46.0.0 (Ubuntu 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.023 secs / 0.018 secs)
  </code></pre>