是否可以重置通话记录,但行为仍然存在?
Is it possible to reset calls history, but persist behavior?
我想写一个像这样的默认模拟:
const myStub = sinon.stub().withArgs('myArg').returns('someValue');
在我的测试中,我只想重置 beforeEach
处理程序中 myStub
的调用历史记录,但保持其默认行为。这样我就不用每次想用的时候都重新赋值了。
我知道有 reset
方法可以完全重置存根,resetBehavior
可以重置存根的行为。但是我们有什么方法可以只重置调用历史吗?
来自官方文档 http://sinonjs.org/releases/v4.1.2/stubs/ for stub.reset
:
Resets both behaviour and history of the stub.
This is equivalent to calling both stub.resetBehavior() and
stub.resetHistory()
试试stub.resetHistory()
我想写一个像这样的默认模拟:
const myStub = sinon.stub().withArgs('myArg').returns('someValue');
在我的测试中,我只想重置 beforeEach
处理程序中 myStub
的调用历史记录,但保持其默认行为。这样我就不用每次想用的时候都重新赋值了。
我知道有 reset
方法可以完全重置存根,resetBehavior
可以重置存根的行为。但是我们有什么方法可以只重置调用历史吗?
来自官方文档 http://sinonjs.org/releases/v4.1.2/stubs/ for stub.reset
:
Resets both behaviour and history of the stub.
This is equivalent to calling both stub.resetBehavior() and stub.resetHistory()
试试stub.resetHistory()