Skip to content

Commit

Permalink
Extract isNonExistentOwnProperty to own function
Browse files Browse the repository at this point in the history
  • Loading branch information
mroderick committed Apr 30, 2018
1 parent c374542 commit 6aad05a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/sinon/sandbox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

var collectOwnMethods = require("./collect-own-methods");
var isNonExistentOwnProperty = require("./util/core/is-non-existent-own-property");
var sinonMatch = require("./match");
var sinonAssert = require("./assert");
var sinonClock = require("./util/fake_timers");
Expand Down Expand Up @@ -151,8 +152,7 @@ function Sandbox() {
};

sandbox.stub = function stub(object, property) {
if (object && typeof property !== "undefined"
&& !(property in object)) {
if (isNonExistentOwnProperty(object, property)) {
throw new TypeError("Cannot stub non-existent own property " + valueToString(property));
}

Expand Down
3 changes: 2 additions & 1 deletion lib/sinon/stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var behavior = require("./behavior");
var behaviors = require("./default-behaviors");
var isNonExistentOwnProperty = require("./util/core/is-non-existent-own-property");
var spy = require("./spy");
var extend = require("./util/core/extend");
var functionToString = require("./util/core/function-to-string");
Expand All @@ -25,7 +26,7 @@ function stub(object, property) {

throwOnFalsyObject.apply(null, arguments);

if (object && typeof property !== "undefined" && !(property in object)) {
if (isNonExistentOwnProperty(object, property)) {
throw new TypeError("Cannot stub non-existent own property " + valueToString(property));
}

Expand Down
7 changes: 7 additions & 0 deletions lib/sinon/util/core/is-non-existent-own-property.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"use strict";

function isNonExistentOwnProperty(object, property) {
return object && typeof property !== "undefined" && !(property in object);
}

module.exports = isNonExistentOwnProperty;

0 comments on commit 6aad05a

Please sign in to comment.