diff --git a/lib/sinon/util/core.js b/lib/sinon/util/core.js index 9ca9a8752..f91283403 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; 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 = {};