Skip to content

Commit

Permalink
Document/test call ordering checks
Browse files Browse the repository at this point in the history
Apparently sinon call instances also have `called(Immediately)?(Before|After)` methods like spies, but this is not documented. Add documentation.
  • Loading branch information
jpage-godaddy authored and fatso83 committed Jun 8, 2018
1 parent e68ba0d commit 78f7549
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/release-source/release/spy-call.md
Expand Up @@ -73,6 +73,28 @@ Returns `true` if call threw exception of provided type.
Returns `true` if call threw provided exception object.


### `spyCall.calledBefore(otherCall)`

Returns `true` if the spy call occurred before another spy call.


### `spyCall.calledAfter(otherCall)`

Returns `true` if the spy call occurred after another spy call.


### `spyCall.calledImmediatelyBefore(otherCall)`

Returns `true` if the spy call occurred before another call, and no calls to any
other spy occurred in-between.


### `spyCall.calledImmediatelyAfter(otherCall)`

Returns `true` if the spy call occurred after another call, and no calls to any
other spy occurred in-between.


### `spyCall.thisValue`

The call's `this` value.
Expand Down
25 changes: 25 additions & 0 deletions test/call-test.js
Expand Up @@ -147,6 +147,31 @@ describe("sinonSpy.call", function () {

assert.same(spy.getCall(0).thisValue, obj);
});

it("has methods to test relative ordering", function () {
var spy = sinonSpy();
for (var i = 0; i < 4; i++) {
spy.call({});
}

var calls = [0, 1, 2, 3].map(function (idx) {
return spy.getCall(idx);
});

assert.equals(calls[1].calledBefore(calls[3]), true);
assert.equals(calls[1].calledBefore(calls[0]), false);

assert.equals(calls[3].calledAfter(calls[1]), true);
assert.equals(calls[1].calledAfter(calls[3]), false);

assert.equals(calls[0].calledImmediatelyBefore(calls[2]), false);
assert.equals(calls[1].calledImmediatelyBefore(calls[2]), true);
assert.equals(calls[3].calledImmediatelyBefore(calls[1]), false);

assert.equals(calls[3].calledImmediatelyAfter(calls[1]), false);
assert.equals(calls[2].calledImmediatelyAfter(calls[1]), true);
assert.equals(calls[1].calledImmediatelyAfter(calls[3]), false);
});
});

describe("call calledOn", function () {
Expand Down

0 comments on commit 78f7549

Please sign in to comment.