Skip to content

Commit

Permalink
Merge pull request #1140 from launchcg-ztonia/hasOwnProperty/override…
Browse files Browse the repository at this point in the history
…/v1.17

Has Own Property Check in Core now compares vs Object prototype.
  • Loading branch information
fatso83 committed Dec 17, 2016
2 parents d11e51f + 50e4709 commit 8663746
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/sinon/util/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions test/mock-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down

0 comments on commit 8663746

Please sign in to comment.