Template for Testing with Jasmine
Drop in your code, drop in your Jasmine specs, and away you go!
by eitanp461
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.0.5/angular-mocks.js"></script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Spec Runner</title>
<script type="text/javascript">
(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();
}
})();
</script>
</head>
<body>
</body>
</html>
JavaScript
//--- CODE --------------------------
var foo = 'bar';
function MyCtrl($scope) {
$scope.name = 'Superhero';
}
var myApp = angular.module('myApp',[]).controller('MyCtrl', MyCtrl);
//--- SPECS -------------------------
describe("foo", function() {
it("has a value of bar", function() {
expect(foo).toBe('bar');
});
});
describe('myApp', function() {
var scope;
var controller;
beforeEach(module('myApp'));
it('says hello', inject(function($rootScope, $controller) {
scope = $rootScope.$new();
controller = $controller('MyCtrl', {'$scope':scope});
expect(scope.name).toBe('Superhero');
}));
});