title: Controller methods call Jasmine unit test suite with Karma in AngularJs
body: <p>I am pretty new to Karma and Jasmine which I am using to write unit tests for my AngularJs application.</p>
  
  <p>While running the test suite functions which I have called to initialize data in my controller is getting called by default. Is there any way to avoid this call while running the test suite?</p>
  
  <p>Find the code snippet below:</p>
  
  <p><code>BaseCtrl.js</code></p>
  
  <pre><code>App.controller('BaseCtrl', ['$scope', '$rootScope', 'Data', function($scope, $rootScope, Data){
      //initialize
      $rootScope.loader = false;
      $rootScope.data = false;
  
      $scope.init = function(){
          $rootScope.loader = true;
          Data.init(function(data){
              $rootScope.loader = false;
              $rootScope.data = data;
          });   
      };
  
      $scope.init();
  }])
  </code></pre>
  
  <p><code>Data.js</code></p>
  
  <pre><code>App.service('Data', ['$http', function($http){
      return {
          init:function(callback){
              $http.get('/url').success(function(response){
                 callback(response);
              });
          }
      };
  }]);
  </code></pre>
  
  <p><code>BaseCtrl.spec.js</code></p>
  
  <pre><code>describe('BaseCtrl', function(){
      beforeEach(module('app'));
  
      var $controller, $rootScope, $scope;
  
      beforeEach(inject(function(_$controller_, _$rootScope_){
          $controller = _$controller_;
          $rootScope = _$rootScope_.$new();
      }));
  
      describe('Loader', function(){
          var controller, $scope = {};
          beforeEach(function(){
              controller = $controller('BaseCtrl', {$scope:$scope, $rootScope:$rootScope});
          });
  
          it('should be false by default', function(){
  
              // Check the default value
              expect($rootScope.loader).toBe(false);
  
              // Some code to determine the call, then
  
              expect($rootScope.loader).toBe(true);
  
              // Some code to determine the call is done, then
  
              expect($rootScope.loader).toBe(false);
          });
      });
  });
  </code></pre>