期待一个间谍,但未定义?

时间:2015-05-24 10:01:49

标签: angularjs tdd jasmine karma-jasmine spy

试图让我的头围绕茉莉花间谍,这就是我的测试:

  $scope.switchTurns = function () {
    $scope.playerTurn = !$scope.playerTurn;
    console.log($scope.centrePileCards.length);
    if ($scope.playerTurn == 1) {
      $scope.pickCard();
    }
  }

我的单元测试如下:

it('should pick one card',function(){
    var controller = createController();
    spyOn(scope,'pickCard')
    scope.switchTurns();
    scope.playerTurn=1;
    expect(scope.pickCard()).toHaveBeenCalled();

  })

我现在收到此错误:

Error : Expected a spy , but got undefined.

建议?

1 个答案:

答案 0 :(得分:21)

=IIF(Parameters!IsSummary.Value, "Report (Summary)", "Report (Detail)") 是方法的结果。在您的情况下,它是scope.pickCard()。 当您使用undefined时,您应该写:

spyOn