diff --git a/lib/sinon/stub.js b/lib/sinon/stub.js index a24d140ea..3ddca0a99 100644 --- a/lib/sinon/stub.js +++ b/lib/sinon/stub.js @@ -6,7 +6,7 @@ var behaviors = require("./default-behaviors"); var createProxy = require("./proxy"); var functionName = require("@sinonjs/commons").functionName; var hasOwnProperty = require("@sinonjs/commons").prototypes.object.hasOwnProperty; -var isNonExistentOwnProperty = require("./util/core/is-non-existent-own-property"); +var isNonExistentProperty = require("./util/core/is-non-existent-property"); var spy = require("./spy"); var extend = require("./util/core/extend"); var getPropertyDescriptor = require("./util/core/get-property-descriptor"); @@ -69,8 +69,8 @@ function stub(object, property) { throwOnFalsyObject.apply(null, arguments); - if (isNonExistentOwnProperty(object, property)) { - throw new TypeError("Cannot stub non-existent own property " + valueToString(property)); + if (isNonExistentProperty(object, property)) { + throw new TypeError("Cannot stub non-existent property " + valueToString(property)); } var actualDescriptor = getPropertyDescriptor(object, property); diff --git a/lib/sinon/util/core/is-non-existent-own-property.js b/lib/sinon/util/core/is-non-existent-own-property.js deleted file mode 100644 index 2df12609a..000000000 --- a/lib/sinon/util/core/is-non-existent-own-property.js +++ /dev/null @@ -1,7 +0,0 @@ -"use strict"; - -function isNonExistentOwnProperty(object, property) { - return object && typeof property !== "undefined" && !(property in object); -} - -module.exports = isNonExistentOwnProperty; diff --git a/lib/sinon/util/core/is-non-existent-property.js b/lib/sinon/util/core/is-non-existent-property.js new file mode 100644 index 000000000..f09dc3650 --- /dev/null +++ b/lib/sinon/util/core/is-non-existent-property.js @@ -0,0 +1,12 @@ +"use strict"; + +/** + * @param {*} object + * @param {String} property + * @returns whether a prop exists in the prototype chain + */ +function isNonExistentProperty(object, property) { + return object && typeof property !== "undefined" && !(property in object); +} + +module.exports = isNonExistentProperty; diff --git a/test/sandbox-test.js b/test/sandbox-test.js index 37c0c2eb6..c4e406ace 100644 --- a/test/sandbox-test.js +++ b/test/sandbox-test.js @@ -562,7 +562,7 @@ describe("Sandbox", function() { function() { sandbox.stub(object, Symbol()); }, - { message: "Cannot stub non-existent own property Symbol()" }, + { message: "Cannot stub non-existent property Symbol()" }, TypeError );