Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #145 from mantoni/master

Fix: spy.reset does not reset fakes created by spy.withArgs
  • Loading branch information...
commit 1ddc2a724499799e45fcd074da2f43429bfb63df 2 parents dceb7e5 + f359ee2
@cjohansen cjohansen authored
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 () {
Please sign in to comment.
Something went wrong with that request. Please try again.