恢复沙箱中的单个存根
Restore single stub in sandbox
sandbox = sinon.sandbox.create();
sandbox.stub(db, 'query', () => {
return Promise.resolve();
});
sandbox.stub(process, 'exit', () => { });
sandbox.restore();
删除所有存根。
我想删除一个存根以便重新存根。例如 query
存根。
这可能吗?我找不到这方面的任何信息。
您可以像这样恢复单个方法:
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();).
sandbox = sinon.sandbox.create();
sandbox.stub(db, 'query', () => {
return Promise.resolve();
});
sandbox.stub(process, 'exit', () => { });
sandbox.restore();
删除所有存根。
我想删除一个存根以便重新存根。例如 query
存根。
这可能吗?我找不到这方面的任何信息。
您可以像这样恢复单个方法:
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();).