gpt4 book ai didi

angularjs - 期待 spy 但未定义?

转载 作者:行者123 更新时间:2023-12-04 01:39:36 27 4
gpt4 key购买 nike

试图让我了解 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.

建议?

最佳答案

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

关于angularjs - 期待 spy 但未定义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30422244/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com