Reputation: 51
When cleaning up, after creating a stub with sinon, you can restore or reset it. Can someone explain to me what the difference between these two are? Or when to use restore and when to use reset?
Upvotes: 5
Views: 2430
Reputation: 10187
When you have the following code:
const stub = sinon.stub(object, "foo");
The original object.foo
method is gone. If you want to restore it, you can do object.foo.restore()
or simply stub.restore()
as a shortcut. In other terms, restore
has an impact on object
.
Whereas stub.reset()
has an impact on stub
itself, resetting both its behavior and its history. (cache data like how many times it has been called, previous calls…)
Upvotes: 6