Skip to content

Commit

Permalink
Fix #851: Do not attempt to re-stub constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
traviskaufman authored and mroderick committed Sep 26, 2015
1 parent 775af99 commit bdb973f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/sinon/stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
// is not Object.prototype
if (
propOwner !== Object.prototype &&
prop !== "constructor" &&
typeof sinon.getPropertyDescriptor(propOwner, prop).value === "function"
) {
stub(object, prop);
Expand Down
24 changes: 24 additions & 0 deletions test/issues/issues-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@
clock = sinon.useFakeTimers(new Date("2015-1-5").getTime());
assert.equals(clock.now, Date.now());
}
},

"#852 - createStubInstance on intherited constructors": {
"must not throw error": function () {
var A = function () {};
var B = function () {};

B.prototype = Object.create(A.prototype);
B.prototype.constructor = A;

refute.exception(function () {
sinon.createStubInstance(B);
});
}
},

"#852(2) - createStubInstance should on same constructor": {
"must be idempotent": function () {
var A = function () {};
refute.exception(function () {
sinon.createStubInstance(A);
sinon.createStubInstance(A);
});
}
}
});
}(this));

0 comments on commit bdb973f

Please sign in to comment.