javascript-恢复沙箱中的单个存根
作者:互联网
sandbox = sinon.sandbox.create();
sandbox.stub(db, 'query', () => {
return Promise.resolve();
});
sandbox.stub(process, 'exit', () => { });
sandbox.restore();删除所有存根.
我想删除一个存根,以便重新启动它.例如查询存根.
这可能吗?我找不到有关此的任何信息.
解决方法:
您可以像这样还原单个方法:
db.query.restore();
针对您的特定情况.
根据sinon文档:
var stub = sinon.stub(object, “method”);
Replaces object.method with a stub function. An exception is thrown if
the property is not already a function.The original function can be restored by calling
object.method.restore(); (or stub.restore();).
查看http://sinonjs.org/releases/v2.3.6/stubs/
标签:sinon,javascript 来源: https://codeday.me/bug/20191112/2024075.html