Sinon: `sinon.resetHistory()`不重置历史记录

创建于 2019-05-08  ·  11评论  ·  资料来源: sinonjs/sinon

根据文档

_[email protected]_
您可以使用sinon.resetHistory()重置所有存根的历史记录

重现

const assert = require('chai').assert;
const sinon = require('sinon');

describe('resetHistory', function() {
  var num = null;


  beforeEach(function() {
    num = sinon.createStubInstance(Number);
  });
  afterEach(() => {
    // Restore the default sandbox here
    sinon.restore();
  });

  describe('called on individual stub method', function() {
    it('should clear "called" status on stub', function() {
      num.toFixed();
      assert.isTrue(num.toFixed.called);
      num.toFixed.resetHistory();
      assert.isFalse(num.toFixed.called);
    });
  });

  describe('called on module', function() {
    it('should clear "called" status on all stubs', function() {
      num.toFixed();
      assert.isTrue(num.toFixed.called);
      sinon.resetHistory();
      assert.isFalse(num.toFixed.called);
    });
  });
});

RunKit演示

实际结果

第二次测试失败:
模块上的“被叫”:应清除所有存根上的“被叫”状态:❌。 [assert.isFalse]期望true为false“”

预期成绩

所有测试通过

Bug Medium Help wanted

所有11条评论

我用zip文件的内容更新了该问题,并将其添加为可运行的RunKit演示,声称它可以运行。

我想协助修正错误

@rpgeeganage请做! 这是我们的入门指南

我意识到此注释更多是功能请求,但是如果“存根实例”对象具有自己的resetHistory() (以及resetBehavior()reset() )方法,那将是很好的选择,无需点击整个沙箱。

@mcow您是否尝试过? Sino自从Sinon版本2开始,存根具有

@ fatso83
非常感谢。 我会努力的。

@ fatso83存根方法具有该功能。 “存根实例”对象createStubInstance()调用的结果(糟糕的术语是sinon的,请不要为错误的沟通而怪我)没有。

@ fatso83
我研究了sinon.resetHistorysinon.createStubInstance
我注意到的是, sinon.createStubInstance不使用sandbox的实现,但是sinon.resetHistory使用sandbox 。 在sinon.resetHistorycollection始终为空。 我会深入研究。

@mcow啊哈,这解释了事情。 我没注意到_instance_位:)希望@rpgeeganage深入研究可以带来一些成果。

@ fatso83 ,由于此更改已合并到master中,因此是否应该关闭此问题?

TG为精明的观察者😄

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

NathanHazout picture NathanHazout  ·  3评论

zimtsui picture zimtsui  ·  3评论

kbirger picture kbirger  ·  3评论

OscarF picture OscarF  ·  4评论

ndhoule picture ndhoule  ·  4评论