Skip to content

Commit 12588b3

Browse files
committed
hack
1 parent 995f388 commit 12588b3

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -410,9 +410,9 @@ documentation if you're not sure).
410410
args])`**
411411

412412
The `thenCallback()` stubbing will assume that the rehearsed invocation has an
413-
additional final argument that takes a function. When invoked by the subject,
414-
testdouble.js will invoke that function and pass whatever arguments were sent to
415-
`thenCallback()`.
413+
additional final argument that takes a callback function. When this stubbing is
414+
satisfied, testdouble.js will invoke that callback function and pass in whatever
415+
arguments were sent to `thenCallback()`.
416416

417417
To illustrate, consider this stubbing:
418418

@@ -434,6 +434,12 @@ return something, callbacks can be configured using the
434434
[td.callback](/docs/5-stubbing-results.md#callback-apis-with-a-callback-argument-at-an-arbitrary-position)
435435
argument matcher.
436436

437+
On one hand, `thenCallback()` can be a great way to write fast and clear
438+
synchronous isolated unit tests of production code that's actually asynchronous.
439+
On the other hand, if it's necessary to verify the subject behaves correctly
440+
over multiple ticks of the event loop, you can control this with the [`defer`
441+
and `delay` options](/docs/5-stubbing-results.md#defer).
442+
437443
#### `td.when().thenThrow()`
438444

439445
**`td.when(__rehearsal__[, options]).thenThrow(new Error('boom'))`**
@@ -451,12 +457,12 @@ the error.
451457

452458
**`td.when(__rehearsal__[, options]).thenDo(function (arg1, arg2) {})`**
453459

454-
For everything else, there is `thenDo()`. `thenDo` takes a function which, for
455-
matching rehearsals, testdouble.js will invoke and forward along all arguments
456-
passed as well as bind the `this` context the test double function was invoked
457-
with. This callback is useful for covering tricky cases not handled elsewhere,
458-
and may be a useful extension point for building on top of the library's
459-
stubbing capabilities.
460+
For everything else, there is `thenDo()`. `thenDo` takes a function which will
461+
be invoked whenever satisfied with all the arguments and bound to the same
462+
`this` context that the test double function was actually invoked with. This
463+
callback is useful for covering tricky cases not handled elsewhere, and may be a
464+
potential extension point for building on top of the library's stubbing
465+
capabilities.
460466

461467
### `td.verify()` for verifying interactions
462468

0 commit comments

Comments
 (0)