Skip to content

Commit 1fe433e

Browse files
committed
[fix] stubs restore prototype props correctly
closes #2226
1 parent 3031027 commit 1fe433e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/sinon/default-behaviors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ var defaultBehaviors = {
258258
Object.defineProperty(rootStub.rootObj, rootStub.propName, {
259259
value: newVal,
260260
enumerable: true,
261-
configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName)
261+
configurable: rootStub.shadowsPropOnPrototype || isPropertyConfigurable(rootStub.rootObj, rootStub.propName)
262262
});
263263

264264
return fake;

lib/sinon/stub.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,14 @@ function stub(object, property) {
9494
var func = typeof actualDescriptor.value === "function" ? actualDescriptor.value : null;
9595
var s = createStub(func);
9696

97+
var propIsOwn = Boolean(actualDescriptor.isOwn);
98+
9799
extend.nonEnum(s, {
98100
rootObj: object,
99101
propName: property,
102+
shadowsPropOnPrototype: !propIsOwn,
100103
restore: function restore() {
101-
if (actualDescriptor !== undefined) {
104+
if (actualDescriptor !== undefined && propIsOwn) {
102105
Object.defineProperty(object, property, actualDescriptor);
103106
return;
104107
}

0 commit comments

Comments
 (0)