Skip to content

Commit 9694bb3

Browse files
authored
Merge pull request #504 from Trim/document-replaceesm-api
add documentation for td.replaceEsm API
2 parents af7cdb6 + 2645daf commit 9694bb3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/7-replacing-dependencies.md

+25
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,31 @@ path shouldn't exist yet, a second argument `manualReplacement` can be provided
351351
to short-circuit any attempts to load and imitate a module at
352352
`relativePathToModule`.
353353

354+
## td.replaceEsm() API
355+
356+
`td.replaceEsm` can only be used to replace ESM module compared to `td.replace`
357+
which can either replace properties on object or replace a Nodejs module.
358+
359+
### td.replaceEsm(relativePathToModule)
360+
361+
Without any argument, `td.replaceEsm` will imitate the module with all exported
362+
properties replaced with `td.function()`.
363+
364+
### td.replaceEsm(relativePathToModule, namedExportReplacements, defaultExportReplacement)
365+
366+
When you need to give replacement implementations, you can do it by giving
367+
`namedExportReplacements` and `defaultExportReplacement` arguments.
368+
369+
`namedExportReplacements` is an object to be used to replace ESM named exports.
370+
Each object properties will have its key matching the export name and value
371+
must be the implementation to use.
372+
373+
`defaultExportReplacement` is used to replace the default export and can be
374+
directly the implementation to use as default export.
375+
376+
See [quibble ESM API](https://github.com/testdouble/quibble#quibble-esm-api)
377+
for more information and note about mocking internal Node.js modules.
378+
354379
***
355380
Previous: [Verifying interactions](6-verifying-invocations.md#verifying-interactions)
356381
Next: [Custom argument matchers](8-custom-matchers.md#custom-argument-matchers)

0 commit comments

Comments
 (0)