Skip to content

Commit

Permalink
Add calledOnceWith and calledOnceWithExactly
Browse files Browse the repository at this point in the history
Fixes #116.
  • Loading branch information
JayAndCatchFire authored and domenic committed May 23, 2018
1 parent 293401a commit 9fa3b07
Show file tree
Hide file tree
Showing 4 changed files with 314 additions and 104 deletions.
129 changes: 27 additions & 102 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,108 +28,33 @@ expect(mySpy).to.have.been.calledWith("foo");
All of your favorite Sinon.JS assertions made their way into Sinon–Chai. We show the `should` syntax here; the `expect`
equivalent is also available.

<table>
<thead>
<tr>
<th>Sinon.JS property/method</th>
<th>Sinon–Chai assertion</th>
</tr>
</thead>
<tbody>
<tr>
<td>called</td>
<td>spy.should.have.been.called</td>
</tr>
<tr>
<td>callCount</td>
<td>spy.should.have.callCount(n)</td>
</tr>
<tr>
<td>calledOnce</td>
<td>spy.should.have.been.calledOnce</td>
</tr>
<tr>
<td>calledTwice</td>
<td>spy.should.have.been.calledTwice</td>
</tr>
<tr>
<td>calledThrice</td>
<td>spy.should.have.been.calledThrice</td>
</tr>
<tr>
<td>calledBefore</td>
<td>spy1.should.have.been.calledBefore(spy2)</td>
</tr>
<tr>
<td>calledAfter</td>
<td>spy1.should.have.been.calledAfter(spy2)</td>
</tr>
<tr>
<td>calledImmediatelyBefore</td>
<td>spy.should.have.been.calledImmediatelyBefore(spy2)</td>
</tr>
<tr>
<td>calledImmediatelyAfter</td>
<td>spy.should.have.been.calledImmediatelyAfter(spy2)</td>
</tr>
<tr>
<td>calledWithNew</td>
<td>spy.should.have.been.calledWithNew</td>
</tr>
<tr>
<td>alwaysCalledWithNew</td>
<td>spy.should.always.have.been.calledWithNew</td>
</tr>
<tr>
<td>calledOn</td>
<td>spy.should.have.been.calledOn(context)</td>
</tr>
<tr>
<td>alwaysCalledOn</td>
<td>spy.should.always.have.been.calledOn(context)</td>
</tr>
<tr>
<td>calledWith</td>
<td>spy.should.have.been.calledWith(...args)</td>
</tr>
<tr>
<td>alwaysCalledWith</td>
<td>spy.should.always.have.been.calledWith(...args)</td>
</tr>
<tr>
<td>calledWithExactly</td>
<td>spy.should.have.been.calledWithExactly(...args)</td>
</tr>
<tr>
<td>alwaysCalledWithExactly</td>
<td>spy.should.always.have.been.calledWithExactly(...args)</td>
</tr>
<tr>
<td>calledWithMatch</td>
<td>spy.should.have.been.calledWithMatch(...args)</td>
</tr>
<tr>
<td>alwaysCalledWithMatch</td>
<td>spy.should.always.have.been.calledWithMatch(...args)</td>
</tr>
<tr>
<td>returned</td>
<td>spy.should.have.returned(returnVal)</td>
</tr>
<tr>
<td>alwaysReturned</td>
<td>spy.should.have.always.returned(returnVal)</td>
</tr>
<tr>
<td>threw</td>
<td>spy.should.have.thrown(errorObjOrErrorTypeStringOrNothing)</td>
</tr>
<tr>
<td>alwaysThrew</td>
<td>spy.should.have.always.thrown(errorObjOrErrorTypeStringOrNothing)</td>
</tr>
</tbody>
</table>
| Sinon.JS property/method | Sinon–Chai assertion |
|--------------------------|-------------------------------------------------------------------|
| called | spy.should.have.been.called |
| callCount | spy.should.have.callCount(n) |
| calledOnce | spy.should.have.been.calledOnce |
| calledTwice | spy.should.have.been.calledTwice |
| calledThrice | spy.should.have.been.calledThrice |
| calledBefore | spy1.should.have.been.calledBefore(spy2) |
| calledAfter | spy1.should.have.been.calledAfter(spy2) |
| calledImmediatelyBefore | spy.should.have.been.calledImmediatelyBefore(spy2) |
| calledImmediatelyAfter | spy.should.have.been.calledImmediatelyAfter(spy2) |
| calledWithNew | spy.should.have.been.calledWithNew |
| alwaysCalledWithNew | spy.should.always.have.been.calledWithNew |
| calledOn | spy.should.have.been.calledOn(context) |
| alwaysCalledOn | spy.should.always.have.been.calledOn(context) |
| calledWith | spy.should.have.been.calledWith(...args) |
| alwaysCalledWith | spy.should.always.have.been.calledWith(...args) |
| calledOnceWith | spy.should.always.have.been.calledOnceWith(...args) |
| calledWithExactly | spy.should.have.been.calledWithExactly(...args) |
| alwaysCalledWithExactly | spy.should.always.have.been.calledWithExactly(...args) |
| calledOnceWithExactly | spy.should.always.have.been.calledOnceWithExactly(...args) |
| calledWithMatch | spy.should.have.been.calledWithMatch(...args) |
| alwaysCalledWithMatch | spy.should.always.have.been.calledWithMatch(...args) |
| returned | spy.should.have.returned(returnVal) |
| alwaysReturned | spy.should.have.always.returned(returnVal) |
| threw | spy.should.have.thrown(errorObjOrErrorTypeStringOrNothing) |
| alwaysThrew | spy.should.have.always.thrown(errorObjOrErrorTypeStringOrNothing) |

For more information on the behavior of each assertion, see
[the documentation for the corresponding spy methods][spymethods]. These of course work on not only spies, but
Expand Down
2 changes: 2 additions & 0 deletions lib/sinon-chai.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@
sinonMethod("calledImmediatelyAfter", "been called immediately after %1");
sinonMethod("calledOn", "been called with %1 as this", ", but it was called with %t instead");
sinonMethod("calledWith", "been called with arguments %*", "%D");
sinonMethod("calledOnceWith", "been called exactly once with arguments %*", "%D");
sinonMethod("calledWithExactly", "been called with exact arguments %*", "%D");
sinonMethod("calledOnceWithExactly", "been called exactly once with exact arguments %*", "%D");
sinonMethod("calledWithMatch", "been called with arguments matching %*", "%D");
sinonMethod("returned", "returned %1");
exceptionalSinonMethod("thrown", "threw", "thrown %1");
Expand Down
Loading

0 comments on commit 9fa3b07

Please sign in to comment.