Testing angular providers with Jasmine

Testing angular providers with Jasmine

HTML

<script src="http://pivotal.github.io/jasmine/lib/jasmine-1.3.1/jasmine.js"></script>
<script src="http://pivotal.github.io/jasmine/lib/jasmine-1.3.1/jasmine-html.js"></script>
<link rel="stylesheet" href="http://pivotal.github.io/jasmine/lib/jasmine-1.3.1/jasmine.css">
<script src="http://code.angularjs.org/1.0.5/angular.js"></script>
<script src="http://code.angularjs.org/1.1.4/angular-mocks.js"></script>

JavaScript

//--- CODE --------------------------
angular.module('myapp.test', [], function () {

}).controller('testcont', function($scope) {
    $scope.a = 10;
});

// --- SPECS -------------------------

describe('controllers', function(){
  var scope;   
  beforeEach(angular.mock.module('myapp.test'));   
  beforeEach(inject(function($controller, $rootScope){    
    scope = $rootScope.$new();
    $controller('testcont', {$scope:scope});
  }));

  it('should', function(){
      expect(scope.a).toBe(10)      
  })

});

// --- Runner -------------------------
(function () {
    var jasmineEnv = jasmine.getEnv();
    jasmineEnv.updateInterval = 1000;

    var htmlReporter = new jasmine.HtmlReporter();

    jasmineEnv.addReporter(htmlReporter);

    jasmineEnv.specFilter = function (spec) {
        return htmlReporter.specFilter(spec);
    };

    var currentWindowOnload = window.onload;

    window.onload = function () {
        if (currentWindowOnload) {
            currentWindowOnload();
        }
        execJasmine();
    };

    function execJasmine() {
        jasmineEnv.execute();
    }

})();