runnerpaul
runnerpaul

Reputation: 7236

Clear sinon stub after test

I have this stub in one of my tests:

sinon.stub(service, 'batchNote')
    .resolves(mResponse);

Is it possible to clear it down after the test? If so, how?

Upvotes: 1

Views: 2871

Answers (1)

1565986223
1565986223

Reputation: 6718

Yes it's possible.

Sinon API have restore method for stubs. From the docs

The original function can be restored by calling object.method.restore(); (or stub.restore())

So using your example you could simply do:

const stub = sinon.stub(service, 'batchNote');
stub.resolves(mResponse);

console.log(service.batchNote()); // outputs stubbed value

stub.restore()
console.log(service.batchNote()); // outputs original

Upvotes: 3

Related Questions