Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs for multiple captor values. #145

Merged
merged 3 commits into from
Oct 12, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/6-verifying-invocations.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,25 @@ argument captors or the perceived need for asynchronous behavior in unit tests.
For related conversation, check out Gary Bernhardt's excellent talk on this topic
called [Boundaries](https://www.destroyallsoftware.com/talks/boundaries).

#### Capturing multiple invocations with td.matchers.captor()

In some cases you may want to capture multiple invocations of the same function or
method in one test. A common usecase for this is subscription based APIs where a
callback will be invoked for each message. To handle this usecase, `captors` expose
a `values` array which will hold each argument passed during every invocation of the
callback:

``` javascript
var captor = td.matchers.captor(),
responseCallback = td.function();

subscribe('/chat', responseCallback); // subscribe() will call responseCallback twice
td.verify(responseCallback('/chat', captor.capture()))

assert.equal(captor.values[0], 'first message');
assert.equal(captor.values[1], 'second message');
````

### Configuring verifications

Verifications can be configured in [the exact same ways that stubbings
Expand Down