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

时间:2015-08-17 13:06:53

标签: javascript jasmine

除了在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将在每次测试后撤消任何间谍。

1 个答案:

答案 0 :(得分:3)

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

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