Skip to content

Commit 13b27cc

Browse files
authored
Fix sandbox restore not handling stubbed functions (#2667)
1 parent ae9e09a commit 13b27cc

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lib/sinon/sandbox.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ function Sandbox(opts = {}) {
408408
const [object, property, types] = args;
409409

410410
const isSpyingOnEntireObject =
411-
typeof property === "undefined" && typeof object === "object";
411+
typeof property === "undefined" &&
412+
(typeof object === "object" || typeof object === "function");
412413

413414
if (isSpyingOnEntireObject) {
414415
const ownMethods = collectOwnMethods(spy);

test/sandbox-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,17 @@ describe("Sandbox", function () {
17661766

17671767
assert.isUndefined(o.foo.callCount);
17681768
});
1769+
1770+
it("restores all fields of a stubbed function", function () {
1771+
const sandbox = new Sandbox();
1772+
const o = function () {};
1773+
o.foo = function () {};
1774+
1775+
sandbox.stub(o);
1776+
sandbox.restore();
1777+
1778+
assert.isUndefined(o.foo.callCount);
1779+
});
17691780
});
17701781

17711782
describe("configurable sandbox", function () {

0 commit comments

Comments
 (0)