undefined不是一个对象(评估'$scope.students.pay')

undefined is not an object (evaluating '$scope.students.pay')

本文关键字:scope students pay 评估 undefined 一个对象      更新时间:2023-09-26

我有一个这样的测试:

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')

解决方案附在下面:

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)
});

现在运行它,它应该可以工作。