我的角度控制器是:
myapp.controller('newConsultant', ['$scope', '$http', '$location', function($scope, $http, $location) {
$scope.save = function(data) {
console.log("assignment data is:" + data);
$scope.input = data;
if ($scope.assignment.$valid)
{
$http.post('./ccs/enrollment/save', $scope.input).success(function(data) {
$location.path('/ldp/lem/el');
});
}
};
}]);
我的控制器规格是:
describe('controller: newConsultant', function() {
beforeEach(inject(function($controller){
scope={};
$controller('newConsultant',{$scope:scope});
}));
it('check for save function defined or not',function(){
expect('save').toBeDefined();
});
it('check for save function defined or not', function() {
scope.save(2);
expect(scope.input).toEqual(2);
});
});
当我测试此代码时,karma发送了一个错误:TypeError:无法读取属性' $ valid'未定义的 at Object。$ scope.save 第一次测试成功运行,但我在第二次测试时遇到错误。 请任何人帮助我。谢谢。