Skip to content

sinon.restore cannot restore spies #2491

@runspired

Description

@runspired

Version: 15.0.1

Assuming a class instance like so

class Thing {
  aMethod() {}
}
const thing = new Thing();

and a spy like so

sinon.spy(thing, 'aMethod');

a global restore will error

sinon.restore();

This is because sinon attempts to directly set target[property] back to the original method, which is caught by the spy proxy.

Example Error:

TypeError: Cannot assign to read only property 'setRequestReviewers' of object '[object Object]'
         at Function.restore 

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