@@ -410,9 +410,9 @@ documentation if you're not sure).
410
410
args])` **
411
411
412
412
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 ()`.
416
416
417
417
To illustrate, consider this stubbing:
418
418
@@ -434,6 +434,12 @@ return something, callbacks can be configured using the
434
434
[ td.callback] ( /docs/5-stubbing-results.md#callback-apis-with-a-callback-argument-at-an-arbitrary-position )
435
435
argument matcher.
436
436
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
+
437
443
#### ` td.when().thenThrow() `
438
444
439
445
** ` td.when(__rehearsal__[, options]).thenThrow(new Error('boom')) ` **
@@ -451,12 +457,12 @@ the error.
451
457
452
458
** ` td.when(__rehearsal__[, options]).thenDo(function (arg1, arg2) {}) ` **
453
459
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.
460
466
461
467
### ` td.verify() ` for verifying interactions
462
468
0 commit comments