-
-
Notifications
You must be signed in to change notification settings - Fork 780
Description
Describe the bug
When using sinon.spy(<obj>) the method sinon.restore() does not restore the object back to the original state.
This is very useful for mocha (other) tests which use beforeEach/afterEach to restore the object to previous states.
A workaround I'm using is sinon.spy(<obj>, "method_name") as this works as expected and sinon.restore() removes the wrapped methods.
To Reproduce
See https://runkit.com/olirogers/sinon-restore-issue/2.0.0
Steps to reproduce the behavior:
- Wrap an object
- (Optionally) run some tests on it
- Restore the sandbox/sinon
- Wrap the object again
- Receive an error that
Attempted to wrap <method_name> which is already wrapped
Expected behavior
Script to run successfully, restore removes the wrapping of the methods on the object.
Screenshots
N/A - See https://runkit.com/olirogers/sinon-restore-issue/2.0.0
Context (please complete the following information):
- Library version: 8.0.2
- Environment: Node 10.18.0 (from runkit)
- Example URL: https://runkit.com/olirogers/sinon-restore-issue/2.0.0
- Other libraries you are using: @sinonjs/referee (version 4.0.0)
Additional context
This issue was encountered following the official guides at - https://sinonjs.org/releases/latest/spies/, version 1.0.0. of the runkit has an example that should also exhibit this bug (but runkit was being slow!).
The same behaviour is experienced with sinon.reset(). It appears to be calling reset on the object itself (new Foo{}) rather than each of the methods.
I found #1553 but assumed that this should be called automatically from the sandbox/environment restore()?
Let me know if you need any more information.
Oli