我在我的一项测试中有这个 stub :
sinon.stub(service, 'batchNote')
.resolves(mResponse);
测试后可以清除吗?如果是这样,怎么办?
最佳答案
是的,这是可能的。
Sinon
API 为 stub
提供了restore
方法。来自docs
The original function can be restored by calling
object.method.restore()
; (orstub.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
关于javascript - 测试后清除 sinon stub ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57638544/