From bdb973ff0028a9f32ee22b9a27ed2fb97f603740 Mon Sep 17 00:00:00 2001 From: Travis Kaufman Date: Fri, 25 Sep 2015 07:06:00 -0400 Subject: [PATCH] Fix #851: Do not attempt to re-stub constructors --- lib/sinon/stub.js | 1 + test/issues/issues-test.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/sinon/stub.js b/lib/sinon/stub.js index b1fcf1f30..903081ea3 100644 --- a/lib/sinon/stub.js +++ b/lib/sinon/stub.js @@ -54,6 +54,7 @@ // is not Object.prototype if ( propOwner !== Object.prototype && + prop !== "constructor" && typeof sinon.getPropertyDescriptor(propOwner, prop).value === "function" ) { stub(object, prop); diff --git a/test/issues/issues-test.js b/test/issues/issues-test.js index 0893c1ffc..d4bac345b 100644 --- a/test/issues/issues-test.js +++ b/test/issues/issues-test.js @@ -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));