CallThrough injected spy

我们两清 提交于 2019-12-13 12:50:43

问题


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.

thanks


回答1:


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,

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


来源:https://stackoverflow.com/questions/38919057/callthrough-injected-spy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!