@@ -97,7 +97,7 @@ replaces all functions it encounters with fake test double functions which can,
97
97
in turn, be configured by your test to either stub responses or assert
98
98
invocations.
99
99
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
101
101
[ here] ( docs/7-replacing-dependencies.md#how-module-replacement-works-for-es-modules-using-import ) .
102
102
103
103
#### Module replacement with Node.js
@@ -568,6 +568,37 @@ completeness—a test will verify an invocation that already satisfied a stubbin
568
568
but this is almost [ provably
569
569
unnecessary] ( /docs/B-frequently-asked-questions.md#why-shouldnt-i-call-both-tdwhen-and-tdverify-for-a-single-interaction-with-a-test-double ) .
570
570
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
+
571
602
### Other functions
572
603
573
604
For other top-level features in the testdouble.js API, consult the [ docs] ( /docs )
0 commit comments