@@ -109,17 +109,19 @@ module.exports = {
109
109
```
110
110
111
111
In the above example, at the point when ` src/index ` is required, the module
112
- cache will be bypassed, and if ` index ` goes on to subsequently require any of
113
- the ` td.replace() ` 'd dependencies, it will receive a reference to the same fake
114
- dependencies that were returned to the test.
112
+ cache will be bypassed as ` index ` is loaded. If ` index ` goes on to subsequently
113
+ require any of the ` td.replace() ` 'd dependencies, it will receive a reference to
114
+ the same fake dependencies that were returned to the test.
115
115
116
116
Because ` td.replace() ` first loads the actual file, it will do its best to
117
117
return a fake that is shaped just like the real thing. That means that if
118
118
` loads-purchases ` exports a function, a test double function will be created and
119
- returned. If ` generates-invoice ` exports a constructor, the constructor and all
120
- of its static and instance methods will be replaced with test double functions.
121
- If ` sends-invoice ` exports a plain object of function properties, each function
122
- will be replaced with a test double (and the other values cloned).
119
+ returned. If ` generates-invoice ` exports a constructor, a constructor test
120
+ double will be returned, complete with test doubles for all of the original's
121
+ static functions and instance methods. If ` sends-invoice ` exports a plain
122
+ object of function properties, an object will be returned with test double
123
+ functions in place of the originals' function properties. In every case, any
124
+ non-function properties will be deep-cloned.
123
125
124
126
There are a few important things to keep in mind about replacing Node.js modules
125
127
using ` td.replace() ` :
@@ -137,16 +139,16 @@ using `td.replace()`:
137
139
##### Default exports with ES modules
138
140
139
141
If your modules are written in the ES module syntax and they specify default
140
- exports, just remember that you'll need to reference ` .default ` when translating
141
- to CJS syntax .
142
+ exports (e.g. ` export default function loadsPurcases() ` ), just remember that
143
+ you'll need to reference ` .default ` when translating to the CJS module format .
142
144
143
145
That means instead of this:
144
146
145
147
``` js
146
148
loadsPurchases = td .replace (' ../src/loads-purchases' )
147
149
```
148
150
149
- You probable mean to assign the fake like this:
151
+ You probably want to assign the fake like this:
150
152
151
153
``` js
152
154
loadsPurchases = td .replace (' ../src/loads-purchases' ).default
@@ -195,7 +197,8 @@ could have called `td.replace(app.signup, 'onCancel')`, instead.
195
197
196
198
Remember to call ` td.reset() ` in an after-each hook (preferably globally so one
197
199
doesn't have to remember to do so in each-and-every test) so that testdouble.js
198
- can replace the original is crucial to avoiding hard-to-debug test pollution!
200
+ can replace the original. This is crucial to avoiding hard-to-debug test
201
+ pollution!
199
202
200
203
#### Specifying a custom replacement
201
204
@@ -248,9 +251,10 @@ double function and can be called in three modes:
248
251
* ** ` td.func() ` ** - returns an anonymous test double function that can be used
249
252
for stubbing and verifying any calls against it, but whose error messages and
250
253
debugging output won't have a name to trace back to it
251
- * ** ` td.func('some name') ` ** - returns a test double function named 'some name',
252
- which will appear in any error messages as well as the debug info returned by
253
- passing the returned test double into ` td.explain() `
254
+ * ** ` td.func('some name') ` ** - returns a test double function named `'some
255
+ name'`, which will appear in any error messages as well as the debug info
256
+ returned by passing the returned test double into
257
+ [ td.explain()] ( /docs/9-debugging.md#tdexplainsometestdouble )
254
258
255
259
#### ` td.object() `
256
260
@@ -265,7 +269,7 @@ and supports three types of invocations:
265
269
test double named ` '.invoices.send' ` )
266
270
* ** ` td.object(['add', 'subtract']) ` ** - returns a plain JavaScript object
267
271
containing two properties ` add ` and ` subtract ` that are both assigned to test
268
- double functions named ` '.add' ` and ` '.subtract' ` , respectively.
272
+ double functions named ` '.add' ` and ` '.subtract' ` , respectively
269
273
* ** ` td.object('a Person'[, {excludeMethods: ['then']}) ` ** - when passed with no
270
274
args or with a string name as the first argument, returns an [ ES
271
275
Proxy] ( https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy ) .
@@ -280,8 +284,8 @@ If your code depends on ES classes or functions intended to be called with
280
284
well.
281
285
282
286
* ** ` td.constructor(RealConstructor) ` ** - returns a constructor whose calls can
283
- be verified and whose ` prototype ` functions have all been replaced with test
284
- double functions using the same
287
+ be verified and whose static and ` prototype ` functions have all been replaced
288
+ with test double functions using the same
285
289
[ imitation] ( https://github.com/testdouble/testdouble.js/blob/master/src/imitate/index.js )
286
290
mechanism described above
287
291
* ** ` td.constructor(['select', 'save']) ` ** - returns a constructor with ` select `
@@ -337,10 +341,9 @@ object](/docs/5-stubbing-results.md#configuring-stubbings) as a second
337
341
parameter, which enables advanced usage like ignoring extraneous arguments and
338
342
limiting the number of times a stubbing can be satisfied.
339
343
340
- Calling ` td.when() ` returns an object of functions that each represent
341
- the type of outcome you want to configure whenever the test double is invoked as
342
- demonstrated by your rehearsal, which we'll describe below, beginning with
343
- ` thenReturn ` .
344
+ Calling ` td.when() ` returns a number of functions that allow you to specify your
345
+ desired outcome when the test double is invoked as demonstrated by your
346
+ rehearsal. We'll begin with the most common of these: ` thenReturn ` .
344
347
345
348
#### ` td.when().thenReturn() `
346
349
@@ -378,7 +381,7 @@ hitCounter() // 1
378
381
hitCounter () // 2
379
382
hitCounter () // 3
380
383
hitCounter () // 4
381
- hitCounter () // 5
384
+ hitCounter () // 4
382
385
```
383
386
384
387
#### ` td.when().thenResolve() ` and ` td.when().thenReject() `
0 commit comments