繁体   English   中英

在Jasmine中,我如何删除一个间谍方法?

[英]In Jasmine, how do I stub out a spied upon method?

除了在Jasmine中监视它之外,我想要一个函数。 我怎样才能做到这一点?

var o = { foo: function(){} };
var spy = spyOn(o, 'foo')
  .andStubWith(function() { console.log('foo'); }); // This is pseudocode - is there a real equivalent?

我不想在我的测试中简单地覆盖函数的原因是IIUC,Jasmine将在每次测试后撤消任何间谍。

请参阅http://jasmine.github.io/2.0/introduction.html#section-Spies:_和and.callFake

spyOn(o, "foo").and.callFake(function() {
  console.log('foo')
  return 1001;
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM