Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/sinon/restore-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export default function restoreObject(object) {
);
}

return walkObject(restore, object, filter);
return walkObject(restore, object, filter, false);
}
5 changes: 3 additions & 2 deletions src/sinon/util/core/walk-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ import walk from "./walk.js";
* @param {ObjectMutator} mutator called on each property
* @param {object} object the object we are walking over
* @param {ObjectFilter} filter a predicate (boolean function) that will decide whether or not to apply the mutator to the current property
* @param {boolean} [strict] when true (default), throws if the mutator was never applied to any property
* @returns {void} nothing
*/
const walkObject = function (mutator, object, filter) {
const walkObject = function (mutator, object, filter, strict = true) {
let called = false;
const name = functionName(mutator);

Expand Down Expand Up @@ -56,7 +57,7 @@ const walkObject = function (mutator, object, filter) {
}
});

if (!called) {
if (!called && strict) {
throw new Error(
`Found no methods on object to which we could apply mutations`,
);
Expand Down
22 changes: 9 additions & 13 deletions test/src/restore-object-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,15 @@ describe("restore-object", function () {
);
});

it("throws with no spies or stubs", function () {
assert.exception(
function () {
restoreObject({
catpants: function () {},
meh: "okay",
});
},
{
message:
"Found no methods on object to which we could apply mutations",
},
);
it("is a no-op with no spies or stubs", function () {
const object = {
catpants: function () {},
meh: "okay",
};

refute.exception(function () {
restoreObject(object);
});
});

it("works with mixed spies and stubs", function () {
Expand Down