Browse files

Merge pull request #145 from mantoni/master

Fix: spy.reset does not reset fakes created by spy.withArgs
  • Loading branch information...
2 parents dceb7e5 + f359ee2 commit 1ddc2a724499799e45fcd074da2f43429bfb63df @cjohansen cjohansen committed Jun 20, 2012
Showing with 42 additions and 15 deletions.
  1. +5 −0 lib/sinon/spy.js
  2. +37 −15 test/sinon/spy_test.js
View
5 lib/sinon/spy.js
@@ -120,6 +120,11 @@
this.thisValues = [];
this.exceptions = [];
this.callIds = [];
+ if (this.fakes) {
+ for (var i = 0; i < this.fakes.length; i++) {
+ this.fakes[i].reset();
+ }
+ }
},
create: function create(func) {
View
52 test/sinon/spy_test.js
@@ -2282,13 +2282,8 @@ if (typeof require === "function" && typeof module === "object") {
}
},
- "reset": {
- "resets spy state": function () {
- var spy = sinon.spy();
- spy();
-
- spy.reset();
-
+ "reset": (function () {
+ function assertReset(spy) {
assert(!spy.called);
assert(!spy.calledOnce);
assert.equals(spy.args.length, 0);
@@ -2299,18 +2294,45 @@ if (typeof require === "function" && typeof module === "object") {
assert.isNull(spy.secondCall);
assert.isNull(spy.thirdCall);
assert.isNull(spy.lastCall);
- },
+ }
+
+ return {
+ "resets spy state": function () {
+ var spy = sinon.spy();
+ spy();
- "resets call order state": function () {
- var spies = [sinon.spy(), sinon.spy()];
- spies[0]();
- spies[1]();
+ spy.reset();
- spies[0].reset();
+ assertReset(spy);
+ },
- assert(!spies[0].calledBefore(spies[1]));
+ "resets call order state": function () {
+ var spies = [sinon.spy(), sinon.spy()];
+ spies[0]();
+ spies[1]();
+
+ spies[0].reset();
+
+ assert(!spies[0].calledBefore(spies[1]));
+ },
+
+ "resets fakes returned by withArgs": function () {
+ var spy = sinon.spy();
+ var fakeA = spy.withArgs("a");
+ var fakeB = spy.withArgs("b");
+ spy("a");
+ spy("b");
+ spy("c");
+ var fakeC = spy.withArgs("c");
+
+ spy.reset();
+
+ assertReset(fakeA);
+ assertReset(fakeB);
+ assertReset(fakeC);
+ }
}
- },
+ }()),
"withArgs": {
"defines withArgs method": function () {

0 comments on commit 1ddc2a7

Please sign in to comment.