Skip to content

Commit

Permalink
Fix: spy.reset did not reset fakes created by spy.withArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
mantoni committed Jun 20, 2012
1 parent dceb7e5 commit f359ee2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
5 changes: 5 additions & 0 deletions lib/sinon/spy.js
Expand Up @@ -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) {
Expand Down
52 changes: 37 additions & 15 deletions test/sinon/spy_test.js
Expand Up @@ -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);
Expand All @@ -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 () {
Expand Down

0 comments on commit f359ee2

Please sign in to comment.