title: Getting error while using Jasmine with AngularJS
body: <p>I am using <strong>jasmin</strong> to test my <strong>AngularJs</strong> project with following code <br></p>
  
  <p><strong>controllersSpec.js</strong> </p>
  
  <pre><code>describe('myApp', function(){
  
      beforeEach(angular.mock.module('myApp'));
  
      it('should have a mailctrl', function() {
          expect(myApp.mailctrl).toBeDefined();
      });
  });
  </code></pre>
  
  <p><strong>controller.js</strong><br></p>
  
  <pre><code>var myApp = angular.module('myApp', []);
  
  myApp.controller('mailctrl', ['$scope', '$routeParams', '$rootScope', 'getMailData', '$angularCacheFactory',
  
      function ($scope, $routeParams, $rootScope, getMailData, $angularCacheFactory) {
             ##....controller content....##
      }
  ]);
  </code></pre>
  
  <p><strong>SpecRunner.html</strong></p>
  
  <p><code>&lt;script type="text/javascript" src="../lib/angular/angular.min.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="lib/jasmine-2.0.0/jasmine.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="lib/jasmine-2.0.0/jasmine.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="lib/jasmine-2.0.0/jasmine-html.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="lib/jasmine-2.0.0/boot.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="../test/lib/angular/angular-mocks.js"&gt;&lt;/script&gt;
    &lt;script src="../js/controller.js"&gt;&lt;/script&gt;
    &lt;script src="../test/unit/controllersSpec.js"&gt;&lt;/script&gt;</code></p>
  
  <p>Now when I am opening <strong>Specrunner.html</strong> in browser, I am getting following error <br><br>
  <strong>Expected undefined to be defined.</strong> <br>
  I have following question regarding above <br><br>
  1) Where I am getting wrong ?<br>
  2) How can I use $rootScope variable of controller ?<br>
  3) Whats the difference in  <em>beforeEach(angular.mock.module('myApp'));</em>  and <em>beforeEach(angular.module('myApp'));</em> and <em>beforeEach(module('myApp'));</em></p>
  
  <p><strong>EDIT :</strong><br><br>
  I have modified the code as  </p>
  
  <pre><code>describe('myApp', function(){
      beforeEach(angular.mock.module('myApp'));        
      it('should have a mailctrl', inject(function($rootScope, $controller) {
          var controller = $controller('mailctrl', { $scope: $rootScope.$new(), $rootScope: $rootScope });
          expect(controller).toBeDefined();
  }));
  </code></pre>
  
  <p>and getting following error - <br><br>
  <strong>Error: [$injector:unpr] <a href="http://errors.angularjs.org/undefined/" rel="nofollow">http://errors.angularjs.org/undefined/</a>$injector/unpr?p0=%24routeParamsProvider%20%3C-%20%24routeParams</strong></p>
  
  <p>If I add other params in $controller() (i.e. '$routeParams', 'getMailData') Error comes as they are undefined.</p>