Skip to content

Instantly share code, notes, and snippets.

@bbraithwaite
Last active February 22, 2019 06:55
Show Gist options
  • Save bbraithwaite/d69d3e68b004bc0d3318 to your computer and use it in GitHub Desktop.
Save bbraithwaite/d69d3e68b004bc0d3318 to your computer and use it in GitHub Desktop.
<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>
@UlyssesAlves
Copy link

UlyssesAlves commented May 20, 2017

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?

@djcard
Copy link

djcard commented Jun 27, 2017

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