2016-07-06 78 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

相關問題