-
-
Save bbraithwaite/d69d3e68b004bc0d3318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<!-- Jasmine References --> | |
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/jasmine.min.css"> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/jasmine.min.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/jasmine-html.min.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.3.3/boot.min.js"></script> | |
<!-- Angular and Angular Mock references --> | |
<script type="text/javascript" src="https://code.angularjs.org/1.4.0-rc.2/angular.min.js"></script> | |
<script type="text/javascript" src="https://code.angularjs.org/1.4.0-rc.2/angular-mocks.js"></script> | |
</head> | |
<body></body> | |
<script type="text/javascript"> | |
angular.module('calculatorApp', []).controller('CalculatorController', function CalculatorController($scope) { | |
$scope.sum = function() { | |
$scope.z = $scope.x + $scope.y; | |
}; | |
}); | |
/* Test Code */ | |
describe('calculator', function () { | |
beforeEach(module('calculatorApp')); | |
var $controller; | |
beforeEach(inject(function(_$controller_){ | |
$controller = _$controller_; | |
})); | |
describe('sum', function () { | |
it('1 + 1 should equal 2', function () { | |
var $scope = {}; | |
var controller = $controller('CalculatorController', { $scope: $scope }); | |
$scope.x = 1; | |
$scope.y = 2; | |
$scope.sum(); | |
expect($scope.z).toBe(3); | |
}); | |
}); | |
}); | |
</script> | |
</html> |
JazzShapka, I'm guessing that the test is written to originally fail on purpose. It can then be changed to pass.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is it possible to put the unit test code in a separate JavaScript file or do I have to always put them inside a HTML page like you did above?