diff --git a/lib/sinon/collection.js b/lib/sinon/collection.js index bda872a57..b5c3b62a7 100644 --- a/lib/sinon/collection.js +++ b/lib/sinon/collection.js @@ -46,7 +46,16 @@ var collection = { }, resetHistory: function resetHistory() { - each(this, "resetHistory"); + getFakes(this).forEach(function (fake) { + if (typeof fake.resetHistory === "function") { + fake.resetHistory(); + return; + } + + if (typeof fake.reset === "function") { + fake.reset(); + } + }); }, verifyAndRestore: function verifyAndRestore() { diff --git a/test/collection-test.js b/test/collection-test.js index 8fd3d0b59..4a7cee4bb 100644 --- a/test/collection-test.js +++ b/test/collection-test.js @@ -365,20 +365,28 @@ describe("collection", function () { beforeEach(function () { this.collection = Object.create(sinonCollection); this.collection.fakes = [{ + // this fake has a resetHistory method resetHistory: sinonSpy() }, { + // this fake has a resetHistory method resetHistory: sinonSpy() + }, { + // this fake pretends to be a spy, which does not have resetHistory method + // but has a reset method + reset: sinonSpy() }]; }); - it("calls resetHistory on all fakes", function () { + it("resets the history on all fakes", function () { var fake0 = this.collection.fakes[0]; var fake1 = this.collection.fakes[1]; + var fake2 = this.collection.fakes[2]; this.collection.resetHistory(); assert(fake0.resetHistory.called); assert(fake1.resetHistory.called); + assert(fake2.reset.called); }); }); diff --git a/test/issues/issues-test.js b/test/issues/issues-test.js index 2c07aa57d..b328a8c0a 100644 --- a/test/issues/issues-test.js +++ b/test/issues/issues-test.js @@ -180,4 +180,21 @@ describe("issues", function () { assert(firstFake !== secondFake); }); }); + + describe("#1372 - sandbox.resetHistory", function () { + it("should reset spies", function () { + var spy = this.sandbox.spy(); + + spy(); + assert.equals(spy.callCount, 1); + + spy(); + assert.equals(spy.callCount, 2); + + this.sandbox.resetHistory(); + + spy(); + assert.equals(spy.callCount, 1); // should not fail but fails + }); + }); });