Clear sinon stub after test(测试后清除SINON存根)
问题描述
我的一个测试中有此存根:
sinon.stub(service, 'batchNote')
.resolves(mResponse);
测试后能不能把它清理掉?如果是,如何?
推荐答案
是的,有可能。
Sinon
API有restore
方法用于stubs
。来自docs
调用
即可恢复原函数object.method.restore()
;(或stub.restore()
)
所以使用您的示例,您可以简单地执行以下操作:
const stub = sinon.stub(service, 'batchNote');
stub.resolves(mResponse);
console.log(service.batchNote()); // outputs stubbed value
stub.restore()
console.log(service.batchNote()); // outputs original
这篇关于测试后清除SINON存根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!