Skip to content

Commit 995f388

Browse files
committed
hack
1 parent 812f970 commit 995f388

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

README.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,19 @@ module.exports = {
109109
```
110110

111111
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.
115115

116116
Because `td.replace()` first loads the actual file, it will do its best to
117117
return a fake that is shaped just like the real thing. That means that if
118118
`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.
123125

124126
There are a few important things to keep in mind about replacing Node.js modules
125127
using `td.replace()`:
@@ -137,16 +139,16 @@ using `td.replace()`:
137139
##### Default exports with ES modules
138140

139141
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.
142144

143145
That means instead of this:
144146

145147
```js
146148
loadsPurchases = td.replace('../src/loads-purchases')
147149
```
148150

149-
You probable mean to assign the fake like this:
151+
You probably want to assign the fake like this:
150152

151153
```js
152154
loadsPurchases = td.replace('../src/loads-purchases').default
@@ -195,7 +197,8 @@ could have called `td.replace(app.signup, 'onCancel')`, instead.
195197

196198
Remember to call `td.reset()` in an after-each hook (preferably globally so one
197199
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!
199202

200203
#### Specifying a custom replacement
201204

@@ -248,9 +251,10 @@ double function and can be called in three modes:
248251
* **`td.func()`** - returns an anonymous test double function that can be used
249252
for stubbing and verifying any calls against it, but whose error messages and
250253
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)
254258

255259
#### `td.object()`
256260

@@ -265,7 +269,7 @@ and supports three types of invocations:
265269
test double named `'.invoices.send'`)
266270
* **`td.object(['add', 'subtract'])`** - returns a plain JavaScript object
267271
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
269273
* **`td.object('a Person'[, {excludeMethods: ['then']})`** - when passed with no
270274
args or with a string name as the first argument, returns an [ES
271275
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
280284
well.
281285

282286
* **`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
285289
[imitation](https://github.com/testdouble/testdouble.js/blob/master/src/imitate/index.js)
286290
mechanism described above
287291
* **`td.constructor(['select', 'save'])`** - returns a constructor with `select`
@@ -337,10 +341,9 @@ object](/docs/5-stubbing-results.md#configuring-stubbings) as a second
337341
parameter, which enables advanced usage like ignoring extraneous arguments and
338342
limiting the number of times a stubbing can be satisfied.
339343

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`.
344347

345348
#### `td.when().thenReturn()`
346349

@@ -378,7 +381,7 @@ hitCounter() // 1
378381
hitCounter() // 2
379382
hitCounter() // 3
380383
hitCounter() // 4
381-
hitCounter() // 5
384+
hitCounter() // 4
382385
```
383386

384387
#### `td.when().thenResolve()` and `td.when().thenReject()`

0 commit comments

Comments
 (0)