Skip to content

Commit

Permalink
Remove misleading 'own' from exception message
Browse files Browse the repository at this point in the history
The property descriptor is recursively retrieved up the
prototype chain. It can by thus often _not_ be owned by
the object. Therefore the previous error message was wrong.
We even have an explicit test for the sandbox.replace* methods
that states this:
    it("should replace an inherited property", ...

This is in opposition to stubs and spies which refuse to replace
fields that are not owned by the object, which is somewhat strange ...
  • Loading branch information
fatso83 committed Jan 4, 2020
1 parent 7cf7dbc commit 8979784
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lib/sinon/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function Sandbox() {
var descriptor = getPropertyDescriptor(object, property);

if (typeof descriptor === "undefined") {
throw new TypeError("Cannot replace non-existent own property " + valueToString(property));
throw new TypeError("Cannot replace non-existent property " + valueToString(property));
}

if (typeof replacement === "undefined") {
Expand Down Expand Up @@ -243,7 +243,7 @@ function Sandbox() {
var descriptor = getPropertyDescriptor(object, property);

if (typeof descriptor === "undefined") {
throw new TypeError("Cannot replace non-existent own property " + valueToString(property));
throw new TypeError("Cannot replace non-existent property " + valueToString(property));
}

if (typeof replacement !== "function") {
Expand Down Expand Up @@ -271,7 +271,7 @@ function Sandbox() {
var descriptor = getPropertyDescriptor(object, property);

if (typeof descriptor === "undefined") {
throw new TypeError("Cannot replace non-existent own property " + valueToString(property));
throw new TypeError("Cannot replace non-existent property " + valueToString(property));
}

if (typeof replacement !== "function") {
Expand Down
6 changes: 3 additions & 3 deletions test/sandbox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ describe("Sandbox", function() {
sandbox.replace({}, "i-dont-exist");
},
{
message: "Cannot replace non-existent own property i-dont-exist",
message: "Cannot replace non-existent property i-dont-exist",
name: "TypeError"
}
);
Expand Down Expand Up @@ -1014,7 +1014,7 @@ describe("Sandbox", function() {
sandbox.replaceGetter({}, "i-dont-exist");
},
{
message: "Cannot replace non-existent own property i-dont-exist",
message: "Cannot replace non-existent property i-dont-exist",
name: "TypeError"
}
);
Expand Down Expand Up @@ -1161,7 +1161,7 @@ describe("Sandbox", function() {
sandbox.replaceSetter({}, "i-dont-exist");
},
{
message: "Cannot replace non-existent own property i-dont-exist",
message: "Cannot replace non-existent property i-dont-exist",
name: "TypeError"
}
);
Expand Down

0 comments on commit 8979784

Please sign in to comment.