测试后清除SINON存根
我的一个测试中有此存根:
sinon.stub(service, 'batchNote')
.resolves(mResponse);
测试后能不能把它清理掉?如果是,如何?
解决方案
是的,有可能。
SinonAPI有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
相关文章