I am running some unit tests based off of this website: http://ift.tt/1S5NWIw
I've wrote an app.js file and a MathController.js file.
Enclosed is the relevant code:
app.js
(function(){
var app = angular.module('app', ['ui-router', 'ng-resource', 'ui-bootstrap']);
// app.config stuff here
}());
MathController.js
(function(){
angular.module('app').controller('MathController', ['$scope', function ($scope){
$scope.sum = function(){
$scope.z = $scope.x + $scope.y;
};
}]);
}());
And here is the test spec file:
MathController.spec.js
describe('MathController', function(){
beforeEach(angular.mock.inject('app'));
var $controller;
beforeEach(angular.mock.inject(function(_$controller_){
$controller = _$controller_;
}));
it('should equal 3', function(){
var $scope = {};
var controller = $controller('MathController', {$scope: $scope });
$scope.x = 1;
$scope.y = 2;
$scope.sum();
expect($scope.z).toBe(3);
});
});
And this is the error I get in the console:
PhantomJS 2.1.1 (Linux 0.0.0) MathController should equal 3 FAILED
Error: [ng:areq] http://ift.tt/1WxbQ3U (line 22)
.....some extra stuff omitted
workFn@/root/lib/angular/angular-mocks.js:2401:26
undefined
Error: [ng:areq] http://ift.tt/1sMPzCh in /home/root/lib/angular/angular.min.js (line 22)
.....some extra stuff omitted
/home/root/spec/MathController.spec.js:13:31
PhantomJS 2.1.1 (Linux 0.0.0): Executed 1 of 1 (1 FAILED) ERROR (0.041 secs / 0.006 secs)
So it says MathController is not a function, and it says angular picked up a string when it should have picked up a function. Can anyone point me in the right direction of how to fix this?
Aucun commentaire:
Enregistrer un commentaire