Skip to content

Commit

Permalink
Fix sinonjs#2226: restoring non-configurable props on prototype chain
Browse files Browse the repository at this point in the history
  • Loading branch information
fatso83 committed Mar 9, 2020
1 parent 4adf2c2 commit 350178b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/sinon/default-behaviors.js
Expand Up @@ -258,7 +258,7 @@ var defaultBehaviors = {
Object.defineProperty(rootStub.rootObj, rootStub.propName, {
value: newVal,
enumerable: true,
configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName)
configurable: rootStub.shadowsPropOnPrototype || isPropertyConfigurable(rootStub.rootObj, rootStub.propName)
});

return fake;
Expand Down
5 changes: 4 additions & 1 deletion lib/sinon/stub.js
Expand Up @@ -94,11 +94,14 @@ function stub(object, property) {
var func = typeof actualDescriptor.value === "function" ? actualDescriptor.value : null;
var s = createStub(func);

var propIsOwn = Boolean(actualDescriptor.isOwn);

extend.nonEnum(s, {
rootObj: object,
propName: property,
shadowsPropOnPrototype: !propIsOwn,
restore: function restore() {
if (actualDescriptor !== undefined) {
if (actualDescriptor !== undefined && propIsOwn) {
Object.defineProperty(object, property, actualDescriptor);
return;
}
Expand Down

0 comments on commit 350178b

Please sign in to comment.