Skip to content

Commit b710f26

Browse files
committed
documentation
1 parent 795b178 commit b710f26

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

README.md

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ replaces all functions it encounters with fake test double functions which can,
9797
in turn, be configured by your test to either stub responses or assert
9898
invocations.
9999

100-
Additionally, if you're using Node 16 or newer, you can replace native ES modules with `td.replaceEsm()`. More details
100+
For ES modules, you should use `td.replaceEsm()`. More details
101101
[here](docs/7-replacing-dependencies.md#how-module-replacement-works-for-es-modules-using-import).
102102

103103
#### Module replacement with Node.js
@@ -568,6 +568,37 @@ completeness—a test will verify an invocation that already satisfied a stubbin
568568
but this is almost [provably
569569
unnecessary](/docs/B-frequently-asked-questions.md#why-shouldnt-i-call-both-tdwhen-and-tdverify-for-a-single-interaction-with-a-test-double).
570570

571+
### `td.listReplacedModules()` for listing the modules that were replaced
572+
573+
**`td.listReplacedModules()`**
574+
575+
576+
If you want to troubleshoot which modules were replaced, you can use
577+
`td.listReplacedModules()`. This function will return an array of the modules that are
578+
currently being replaced via `td.replace()` or `td.replaceEsm()`.
579+
580+
The list is in no particular order, and returns the full path to the module that was replaced.
581+
The path is returned as a `file:` URL as is customary in ESM (this is true even if the
582+
replaced module was CJS).
583+
584+
For example, if you do this:
585+
586+
```js
587+
td.replace('../src/save')
588+
```
589+
590+
Then
591+
592+
```js
593+
td.listReplacedModules()
594+
```
595+
596+
will return something like:
597+
598+
```js
599+
['file:///users/example/code/foo/src/save.js']
600+
```
601+
571602
### Other functions
572603

573604
For other top-level features in the testdouble.js API, consult the [docs](/docs)

0 commit comments

Comments
 (0)