2016-08-12 55 views
0

我正在做一些unitTests,我的場景如下。我有50個測試的服務函數的調用必須相同,但對於單個測試,如果我可以調用原始方法,它將非常有用。我嘗試使用and.callThrough,但它無法正常工作。我試圖越過間諜,但我不能。我做錯了什麼?CallThrough注入間諜

beforeEach(inject(function($controller, _myService_){ 
    spyOn(_myService_, 'getSomeData').and.callFake(function(data, params){ 
     return dummyData; 
    }); 

    createController = function() { 
    return $controller('MyCtrl',{ 
     $uibModalInstance: modalInstance, 
     myService: _myService_, 
     injectedData: injectedData 
    }); 
    }; 
})); 

這是我的測試用例。

it('My test case', function(){ 
    controller = createController(); 
    controller.myService.getSomeData = jasmine.createSpy().and.callThrough() 
}); 

我使用的是茉莉花2.0,測試用例不斷調用callFake函數。

感謝

回答

1

jasmine.createSpy().and.callThrough()不知道該窺探方法,並沒有辦法怎麼能知道它,稱它只是導致調用一個空操作功能。

間諜策略,可以爲現有的間諜被改變,

controller.myService.getSomeData.and.callThrough(); 
+0

謝謝你,解決了我的問題:) – acostela