Skip to content

Commit

Permalink
Added to allow iteration of invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
jonnyreeves committed Sep 8, 2013
1 parent 0c11473 commit 8d69a48
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/sinon/spy.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@
this.callIds[i]);
},

getCalls: function () {
var calls = [];
var i;

for (i = 0; i < this.callCount; i++) {
calls.push(this.getCall(i));
}

return calls;
},

calledBefore: function calledBefore(spyFn) {
if (!this.called) {
return false;
Expand Down
18 changes: 18 additions & 0 deletions test/sinon/spy_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,24 @@ if (typeof require === "function" && typeof module === "object") {
}
},

"getCalls": {
"returns an empty Array by default": function () {
var spy = sinon.spy();

assert.isArray(spy.getCalls());
assert.equals(spy.getCalls().length, 0);
},

"is analogous to using getCall(n)": function () {
var spy = sinon.spy();

spy();
spy();

assert.equals(spy.getCalls(), [ spy.getCall(0), spy.getCall(1) ]);
}
},

"callArg": {
"is function": function () {
var spy = sinon.spy();
Expand Down

0 comments on commit 8d69a48

Please sign in to comment.