Using sinon withArgs and then try to do a restore I get TypeError: 'restore' is not a function

Viewed 127

If I stub my function like so:

const sandbox: sinon.SinonSandbox = sinon.createSandbox();
getInfoStub = sandbox.stub(ytdl, 'getInfo').withArgs(videoUrl).resolves(videoInfo);

And then I try to do getInfoStub.restore() I get a TypeError: getInfoStub.restore is not a function

However when I remove the option .withArgs(videoUrl) restore works fine:

const sandbox: sinon.SinonSandbox = sinon.createSandbox();
getInfoStub = sandbox.stub(ytdl, 'getInfo').resolves(videoInfo);

What's the deal with withArgs that breaks sinon ?

1 Answers

Try below code:

 const getInfoStub = sandbox.stub(ytdl, 'getInfo');
 const result = getInfoStub.withArgs(videoUrl).resolves(videoInfo);
 getInfoStub.restore();

Ref Link: https://sinonjs.org/releases/latest/stubs/

Related