最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Restore single stub in sandbox - Stack Overflow

programmeradmin0浏览0评论
sandbox = sinon.sandbox.create();

sandbox.stub(db, 'query', () => {
    return Promise.resolve();
});

sandbox.stub(process, 'exit', () => { });

sandbox.restore(); removes all the stubs.

I want to remove ONE stub so I can restub it. For example the query stub.

Is this possible? I can't find any information on this.

sandbox = sinon.sandbox.create();

sandbox.stub(db, 'query', () => {
    return Promise.resolve();
});

sandbox.stub(process, 'exit', () => { });

sandbox.restore(); removes all the stubs.

I want to remove ONE stub so I can restub it. For example the query stub.

Is this possible? I can't find any information on this.

Share Improve this question asked Nov 23, 2016 at 10:11 basickarlbasickarl 40.6k69 gold badges238 silver badges355 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

You can restore single method like this:

db.query.restore();

for your particular case.

Per sinon documentation:

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();).

See http://sinonjs/releases/v2.3.6/stubs/

发布评论

评论列表(0)

  1. 暂无评论