Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<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

This comment has been minimized.

Copy link

commented May 16, 2016

Correct line 34. '1 + 2 should equal 3'

@UlyssesAlves

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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
You can’t perform that action at this time.