13

试图了解茉莉花间谍,这就是我的测试的样子:

  $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.

建议?

4

1 回答 1

33

scope.pickCard()是方法的结果。在您的情况下,它是undefined. 当你使用时,spyOn你应该写:

expect(scope.pickCard).toHaveBeenCalled();

于 2015-10-01T14:52:16.623 回答