小编Mar*_*lek的帖子

AngularJs测试Sinon间谍

我是Sinon的新手,所以我想检查一个特定的函数是否被调用,这就是我得到的:

terminalController.controller('CashAcceptorController', [
    'PaymentService',
    '$rootScope',
    '$scope',
    'PayingInfo',
    '$interval',
    '$location',
    function (PaymentService, $rootScope, $scope, PayingInfo, $interval, $location) {
     PaymentService.start();
....
]);
Run Code Online (Sandbox Code Playgroud)

在测试中,我尝试检查在控制器实例化上调用PaymentService.start():

describe('CashAcceptorController', function() {

var PaymentService, rootScope, scope, PayingInfo, $interval, $location;
var mySpy  = sinon.spy(PaymentService.start());;
beforeEach(module('eshtaPayTerminalApp.controllers'));

beforeEach(module('eshtaPayTerminalApp.services'));


beforeEach(inject(function($controller, 
        $rootScope, _PaymentService_, _$interval_, _PayingInfo_) {

    $interval = _$interval_;
    scope = $rootScope.$new();
    rootScope = $rootScope.$new();
    PaymentService = _PaymentService_;
    PayingInfo = _PayingInfo_;

    rootScope.serviceNumber = 'm1';
    rootScope.phoneNumber =  '05135309';

    $controller('CashAcceptorController', {
        $rootScope : rootScope,
        $scope : scope,
        $location : $location,
        _PaymentService_ : PaymentService,
        _$interval_:$interval,
        _PayingInfo_:PayingInfo …
Run Code Online (Sandbox Code Playgroud)

sinon angularjs

2
推荐指数
1
解决办法
2570
查看次数

标签 统计

angularjs ×1

sinon ×1