根据文档:
_自[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);
});
});
});
实际结果
第二次测试失败:
模块上的“被叫”:应清除所有存根上的“被叫”状态:❌。 [assert.isFalse]期望true为false“”
预期成绩
所有测试通过
我用zip文件的内容更新了该问题,并将其添加为可运行的RunKit演示,声称它可以运行。
我想协助修正错误
@rpgeeganage请做! 这是我们的入门指南
我意识到此注释更多是功能请求,但是如果“存根实例”对象具有自己的resetHistory()
(以及resetBehavior()
和reset()
)方法,那将是很好的选择,无需点击整个沙箱。
@mcow您是否尝试过? Sino自从Sinon版本2开始,存根具有
@ fatso83 ,
非常感谢。 我会努力的。
@ fatso83存根方法具有该功能。 “存根实例”对象, createStubInstance()
调用的结果(糟糕的术语是sinon的,请不要为错误的沟通而怪我)没有。
@ fatso83 ,
我研究了sinon.resetHistory
和sinon.createStubInstance
。
我注意到的是, sinon.createStubInstance
不使用sandbox
的实现,但是sinon.resetHistory
使用sandbox
。 在sinon.resetHistory
, collection
始终为空。 我会深入研究。
@mcow啊哈,这解释了事情。 我没注意到_instance_位:)希望@rpgeeganage深入研究可以带来一些成果。
@ fatso83 ,由于此更改已合并到master中,因此是否应该关闭此问题?
TG为精明的观察者😄