diff --git a/lib/sinon/collection.js b/lib/sinon/collection.js index 1579f634a..85a88c189 100644 --- a/lib/sinon/collection.js +++ b/lib/sinon/collection.js @@ -47,12 +47,29 @@ var collection = { }, resetHistory: function resetHistory() { + function privateResetHistory(f) { + var method = f.resetHistory || f.reset; + if (method) { + method.call(f); + } + } + getFakes(this).forEach(function (fake) { - var method = fake.resetHistory || fake.reset; + if (typeof fake === "function") { + privateResetHistory(fake); + return; + } - if (method) { - method.call(fake); + var methods = []; + if (fake.get) { + methods.push(fake.get); + } + + if (fake.set) { + methods.push(fake.set); } + + methods.forEach(privateResetHistory); }); }, diff --git a/test/issues/issues-test.js b/test/issues/issues-test.js index 79bfb8345..5850fbc09 100644 --- a/test/issues/issues-test.js +++ b/test/issues/issues-test.js @@ -390,4 +390,34 @@ describe("issues", function () { mock.verify(); }); }); + + describe("#1648 - resetHistory ", function () { + it("should reset property spies", function () { + var obj = { + func: function () {}, + get prop() { + return 1; + } + }; + + var sandbox = sinon.createSandbox(); + var spyFunc = sandbox.spy(obj, "func"); + var spyProp = sandbox.spy(obj, "prop", ["get"]); + + refute.isTrue(spyFunc.called); + refute.isTrue(spyProp.get.called); + + obj.func(); + //eslint-disable-next-line no-unused-expressions + obj.prop; + + assert.isTrue(spyFunc.called); + assert.isTrue(spyProp.get.called); + + sandbox.resetHistory(); + + refute.isTrue(spyFunc.called); + refute.isTrue(spyProp.get.called); + }); + }); });