小编ilo*_*sti的帖子

为什么 spyOn 在 Jasmine 中“停止所有函数的执行”(要求澄清 Jasmine 2.2 间谍文档)

在 Jasmine 2.2文档中,我无法理解演示 Spies 基本用法的最后一个规范。

beforeEach()我们设置的部分bar = null,然后我们监视foo.setBar然后我们调用foo.setBar两次。我不明白为什么bar === null在最后一个规范中。不应该bar === 456在间谍被拆除之前吗?

这是示例:

describe("About a Spy", function(){
  var foo, bar = null;

  beforeEach(function() {
    foo = {
      setBar: function(value) {
        bar = value;
      }
    };

    spyOn(foo, "setBar"); // we spy

    foo.setBar(123); // shouldn't bar === 123 here?
    foo.setBar(456, 'another param'); // and bar === 456 here?
  });



  it("stops all execution on a function", function() {
    // …
Run Code Online (Sandbox Code Playgroud)

javascript jasmine spyon

5
推荐指数
1
解决办法
1426
查看次数

标签 统计

jasmine ×1

javascript ×1

spyon ×1