$scope.deleteAbc = ->
alert("xyz")
当从test测试此方法时,如何获取警报的值。
describe "XYZ", ->
$scope = null
$controller = null
beforeEach inject ($rootScope,$controller) ->
$scope = $rootScope
ctrl = $controller("StatusController",
$scope: $scope
)
答案 0 :(得分:0)
您可以将AngularJS的$窗口注入控制器并调用$ window.alert(),而不是调用alert()。
您可以在测试中伪造$ window对象。警报变量包含警报消息。
describe "XYZ", ->
$scope = null
$controller = null
alerted = null
beforeEach inject ($rootScope,$controller) ->
$scope = $rootScope
$window:
alert: (message) ->
alerted = message
ctrl = $controller("StatusController",
$scope: $scope
$window: $window
)