CallThrough注入间谍 [英] CallThrough injected spy

查看:48
本文介绍了CallThrough注入间谍的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一些unitTests,我的情况如下.我有50个测试,它们对服务函数的调用必须相同,但是对于一个测试,如果可以调用原始方法,它将很有帮助.我尝试使用and.callThrough,但无法正常工作.我也试图超越间谍,但我不能.我在做什么错了?

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
    });
  };
}));

这是我的测试用例.

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

我正在使用jasmine 2.0,并且该测试用例正在不断调用callFake函数.

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

谢谢

推荐答案

jasmine.createSpy().and.callThrough()并不知道这种间谍方法,而且无法知道它,只是调用它会导致调用noop函数.

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();

这篇关于CallThrough注入间谍的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆