From efe737b1c3109079ecaeeba947b84ad5cec9e4ff Mon Sep 17 00:00:00 2001 From: Zaal Tonia Date: Tue, 6 Sep 2016 17:44:19 -0700 Subject: [PATCH 1/2] Has Own Property Check in Core now compares vs Object prototype. --- lib/sinon/util/core.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/sinon/util/core.js b/lib/sinon/util/core.js index 61f30c732..b79d2bae3 100644 --- a/lib/sinon/util/core.js +++ b/lib/sinon/util/core.js @@ -103,7 +103,8 @@ // IE 8 does not support hasOwnProperty on the window object and Firefox has a problem // when using hasOwn.call on objects from other frames. - var owned = object.hasOwnProperty ? object.hasOwnProperty(property) : hasOwn.call(object, property); + var owned = (object.hasOwnProperty && object.hasOwnProperty === hasOwn) ? + object.hasOwnProperty(property) : hasOwn.call(object, property); if (hasES5Support) { var methodDesc = (typeof method === "function") ? {value: method} : method; From 50e47096cf340f454923bc3d41a2fec689b9e168 Mon Sep 17 00:00:00 2001 From: Zaal Tonia Date: Tue, 6 Sep 2016 18:11:45 -0700 Subject: [PATCH 2/2] Adding a test for the case where an object has Implemented hasOwnProperty --- test/mock-test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/mock-test.js b/test/mock-test.js index 06fcba59f..315de3647 100644 --- a/test/mock-test.js +++ b/test/mock-test.js @@ -906,6 +906,31 @@ } }, + "mock object with hasOwnProperty": { + setUp: function () { + this.method = function () {}; + this.hasOwn = function () { + throw Error("overridden method hasOwnProperty invoked"); + }; + this.object = { method: this.method, hasOwnProperty: this.hasOwn }; + this.mock = sinon.mock.create(this.object); + }, + + "mocks object method": function () { + this.mock.expects("method"); + + assert.isFunction(this.object.method); + refute.same(this.object.method, this.method); + }, + + "reverts mocked method": function () { + this.mock.expects("method"); + this.object.method.restore(); + + assert.same(this.object.method, this.method); + } + }, + "mock method multiple times": { setUp: function () { this.thisValue = {};