Skip to content

Commit

Permalink
regression test for sinonjs#2491
Browse files Browse the repository at this point in the history
  • Loading branch information
fatso83 committed Apr 20, 2023
1 parent 3b41aff commit b4bf432
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/issues/issues-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -822,4 +822,25 @@ describe("issues", function () {
assert.isTrue(fooStubInstance.wasCalled);
});
});

describe("#2491 - unable to restore stubs on an instance where the prototype has an unconfigurable property descriptor", function () {
it("should ensure object descriptors are always configurable", function () {
class BaseClass {}
Object.defineProperty(BaseClass.prototype, "aMethod", {
value: function () {
return 42;
},
});

// anchor
const instance = new BaseClass();
assert.isFunction(instance.aMethod);
assert.equals(instance.aMethod(), 42);
this.sandbox.spy(instance, "aMethod")

refute.exception(() => {
this.sandbox.restore(); // #2491: this throws "TypeError: Cannot assign to read only property 'myMethod' of object '#<BaseClass>'"
});
});
});
});

0 comments on commit b4bf432

Please sign in to comment.