Skip to content

restore() && reset() non-functional if wrapping all object methods #2192

@olirogers

Description

@olirogers

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:

  1. Wrap an object
  2. (Optionally) run some tests on it
  3. Restore the sandbox/sinon
  4. Wrap the object again
  5. 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):

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions