我有这样的测试:
it('calls the stuFun method', function () {
$scope.stuFun();
expect($scope.stuFun).to
.have.been.calledOnce;
expect($scope.students.pay).to.not.equal(null);
assert.isNotTrue($scope.students.pay)
});
以下是我的控制器功能:
$scope.stuFun = function() {
$scope.students.pay = false;
};
为什么我收到以下错误:
undefined is not an object (evaluating '$scope.students.pay')
答案 0 :(得分:1)
解决方案如下:
it('calls the stuFun method', function () {
$scope.students = {};
$scope.stuFun();
expect($scope.stuFun).to
.have.been.calledOnce;
expect($scope.students.pay).to.not.equal(null);
assert.isNotTrue($scope.students.pay)
});
现在运行它,它应该工作。