【问题标题】:In Jasmine, how do I stub out a spied upon method?在 Jasmine 中,我如何消除被监视的方法?
【发布时间】:2015-08-17 13:06:53
【问题描述】:

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

【问题讨论】:

    标签: javascript jasmine


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-04-20
      • 2018-05-10
      • 2017-06-16
      • 2013-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-25
      • 2021-02-04
      相关资源
      最近更新 更多