this repository is a minimal reproduction of argument matching failing for imported functions when using testdouble in an ESM context
- clone this repository
- run
nvm use
to switch your environment to the intended version of node (ornvm install
if you don't already have a matching node version installed) - run
npm clean-install
to install dependencies for the project - run
npm test
to execute the unit tests demonstrating the problems
- the expectation
of
bar
being called withbaz
as the only argument fails even though it is called that way infoo.js
, which is the SUT for that test. This passes as expected in a non-esm environment when usingtd.replace
rather thantd.replaceEsm
baz
has the same identity when imported into the test file and returned from the source file. this is the expected behaviorbaz
does not have the same identity when imported and returned the same way whentd.replaceEsm
is used in the test, even when the replaced module is unrelated.