2016-07-06 79 views
0

我有一个这样的测试对象:

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

回答

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) 

}); 

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

+0

你有一个想法如何嘲笑这种服务... http://stackoverflow.com/questions/38227705/undefined-is-not-an-object-in-angular-js-service – Shane

相关问题