Skip to content

Commit 29d35b1

Browse files
committed
documentation
1 parent 4a40ce8 commit 29d35b1

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

README.md

+31-1
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,36 @@ 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+
Use `td.listReplacedModules()` to list the modules that are replaced. This function will return an array of the modules that are
577+
currently being replaced via `td.replace()` or `td.replaceEsm()`.
578+
579+
The list is in no particular order, and returns the full path to the module that was replaced.
580+
The path is returned as a `file:` URL as is customary in ESM (this is true even if the
581+
replaced module was CJS).
582+
583+
For example, if you do this:
584+
585+
```js
586+
td.replace('../src/save')
587+
```
588+
589+
Then
590+
591+
```js
592+
td.listReplacedModules()
593+
```
594+
595+
will return something like:
596+
597+
```js
598+
['file:///users/example/code/foo/src/save.js']
599+
```
600+
571601
### Other functions
572602

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

0 commit comments

Comments
 (0)