I am failing an angularJS hands-on with the error Check the controller exists or not FAILED even after I defined the controller By the way this is a test case present in the index_test.js index.js is
var app = angular.module('myApp', []);
app.provider('Calculator', function() {
return {
$get : function(){
return {
multiply : function(num1,num2){
return num1*num2;
}
}
}
}
});
app.controller('CalculatorController', function($scope, CalculatorService) {
$scope.answer = null;
$scope.num = 0;
$scope.Square = function() {
$scope.answer = Caluclator.multiply(num,num);
}
$scope.Cube = function() {
$scope.answer = Caluclator.multiply(num,Caluclator.multiply(num,num));
}
});
index.html is
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script>
<script src="index.js"></script>
</head>
<body>
<h1>square, cube using provider!</h1>
<div ng-app="myApp">
<div ng-controller="CalculatorController">
Enter a number:
<input type="number" ng-model="num" />
<button ng-click="Square()">X<sup>2</sup></button>
<button ng-click="Cube()">X<sup>3</sup></button>
<div></div>
</div>
</div>
</body>
</html>
and here is the testing file(index_test.js)
it('Check the controller exists or not', function() {
var $scope = {};
var controller = $controller('CalculatorController', { $scope: $scope });
expect(controller).toBeDefined();
});
Aucun commentaire:
Enregistrer un commentaire