title: Jasmine Testing angularjs controller
body: <p>I am trying to test my controller but I get undefined when running karma start</p>
  
  <p>This is my controller Code:</p>
  
  <pre><code>(function() {
      'use strict';
  
      angular
          .module('tariffOptionsExtras')
          .controller('tariffOptionsExtrasBookCtrl', tariffOptionsExtrasBookCtrl);
  
      tariffOptionsExtrasBookCtrl.$inject = ['tariffOptionsExtrasSrv', '$location', 'cache', 'authSrv', '$stateParams',
          'tariffOptionsExtrasBookSrv', 'minimumDuration', '$rootScope', 'userTypes', 'messageCtrl', '$state'];
  
      function tariffOptionsExtrasBookCtrl(tariffOptionsExtrasSrv, $location, cache, authSrv, stateParams, tariffOptionsExtrasBookSrv, minimumDuration, $rootScope, userTypes, messageCtrl, $state) {
          var vm = this;
          var cacheName = 'tariffOptionsExtras';
  
          var cacheCollection = cache.getCollection(cacheName);
          vm.date = new Date();
          vm.minimumDuration = minimumDuration;
          //if statement commented out. prepaid users should be able to enter the flow.
  Date(vm.bookOption.startDate)
          }
          if (!vm.bookOption) {
              $state.go(pagesConfig.tariffOptionsExtras.name);
  
          } else {
              vm.infoLink = vm.bookOption.infoUrl;
          }
  
          /**
           * Runs booking tarif extra post and in case of success the view is changed
           */
          vm.book = function() {
              //If bookoption not present, redirect to chooser
              tariffOptionsExtrasBookSrv.bookTariffExtra(vm.bookOption).then(function(response) {
                  $rootScope.$broadcast('transactionFinished');
                  var item = response['salesOrderVBO'][0]['orderItems']['orderItem'][0];
                  if (item.product.action == 'BOOKED') {
                      vm.success = true;
                  }
              }, function(reason) {
                  vm.errorMessage = reason.data.faultMessage;
              });
          };
          vm.success = false;
          vm.subscription = authSrv.getUserContract();
          vm.msisdn = vm.subscription.subscription.msisdn;
  
      }
  })();
  </code></pre>
  
  <p>Unit Test with jasmine</p>
  
  <pre><code>describe('tariffOptionsExtras module', function() {
  
  
      describe('tariffOptionsExtrasBook Controller', function() {
          var tariffOptionsExtrasBookCtrl, tariffOptionsExtrasSrv, tariffOptionsExtrasBookSrv, authSrv;
          // Step 1: Import the module this controller belongs to, and its dependencies
          beforeEach(function() {
              module('app.common');
              module('tariffOptionsExtras');
          });
  
          // Step 2: Mock any service that initially used when the controller instantiate
          // beforeEach(module(function($provide) {
  
          //     $provide.factory('tariffOptionsExtrasBookSrv', function() {
          //         var getSync;
          //         getBookedExtras = function() {
          //             return {
          //                 then:function(){}
          //             };
          //         };
          //         getTariffBookableOptions = function() {
          //             return {
          //                 then:function(){}
          //             };
          //         };
          //         return {
          //             getBookedExtras: getBookedExtras,
          //             getTariffBookableOptions:getTariffBookableOptions
          //         };
          //     });
          // }));
          beforeEach(module(function($provide) {
              $provide.factory('authSrv', function() {
                  getUserContract = function() {
                      return {
                          subscription:{
                              msisdn:'491741660390',
                              mboName:'27434975'
                          },
                          contract:{
                              mboName:'27434975',
                              ban:'106491816',
                          }
                      };
                  };
                  return {
                      getUserContract: getUserContract,
                  };
              });
  
          }));
  
  
          // Step 3: Inject $controller with its dependencies
          beforeEach(function() {
              // 1. Import the module
              module('app');
              // 2. Inject $controller
              inject(function($controller, $rootScope, _authSrv_, _tariffOptionsExtrasSrv_, _tariffOptionsExtrasBookSrv_) {
                  authSrv = _authSrv_;
                  tariffOptionsExtrasSrv = _tariffOptionsExtrasSrv_;
                  tariffOptionsExtrasBookSrv = _tariffOptionsExtrasBookSrv_;
  
                  // 3. Use $controller to instantiate the controller
                  tariffOptionsExtrasBookCtrl = $controller('tariffOptionsExtrasBookCtrl', {
                      'authSrv': authSrv,
                      'tariffOptionsExtrasSrv': tariffOptionsExtrasSrv,
                      'tariffOptionsExtrasBookSrv': tariffOptionsExtrasBookSrv
                  });
              });
          });
  
  
          // Step 4: Test the controller
          it('Should return sum of 1+1', function() {
             expect(1+1).toBe(2);
          });
  
      });
  });
  </code></pre>
  
  <p>When running karma Start I get this screen:
  <a href="http://i.stack.imgur.com/JEnbE.jpg" rel="nofollow">enter image description here</a></p>
  
  <p>Also when I comment this block of code it works:</p>
  
  <pre><code>tariffOptionsExtrasBookCtrl = $controller('tariffOptionsExtrasBookCtrl', {
                  'authSrv': authSrv,
                  'tariffOptionsExtrasSrv': tariffOptionsExtrasSrv,
                  'tariffOptionsExtrasBookSrv': tariffOptionsExtrasBookSrv
              });
  </code></pre>