acostela acostela - 2 months ago 3x
Javascript Question

CallThrough injected spy

I'm doing some unitTests and my scenario is the following. I have like 50 tests whose call to a service function must be the same, but for one single test It will be so helpfull if I can call the original method. I tried with the and.callThrough but It's not working correctly. I'm trying to override the spy too but I can't. What I'm doing wrong?

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

This is my test case.

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

I'm using jasmine 2.0 and that test case is continuously calling the callFake function.



jasmine.createSpy().and.callThrough() is unaware of the spied method and there's no way how it can know about it, calling it just results in calling a noop function.

Spying strategy can be changed for existing spies,