New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function identity is different for modules that are not replaced with testdouble when testdouble is replacing other ESM modules #497
Comments
cc/ @giltayar -- is this possibly related to recent changes? |
On it! Great repro repo, @travi. Thank you. |
The tests pass on |
Of course. |
So, yes, after consideration, this is the case discussed in length here: #493 (comment). We decided on keeping the behavior of @searls you were on vacation then, and did not have the time to really consider the alternative. Perhaps now is the time to do so? I still stick with my choice, which is to reload and not surprise the user, at the cost of static identity. But I'm not strong on that decision. I think. |
Is there some sort of alternative in the current state? I'm not necessarily opposed to using a matcher or something along those lines in the |
@travi not sure how a comparison that is not the identity comparison would work. You could implement it yourself by attaching a "hidden" property to the function and checking that. |
Agreed. Just wasn't sure if there was something exposed that I was overlooking. I guess just consider me hopeful that this is a use case that can be enabled in some way. |
Sorry I don't have a better answer. FWIW, one of my initial motivations in writing |
Description
I've been working to migrate some projects to ESM and move from sinon to testdouble in the process. I've found this to be mostly smooth, except when a function is passed to function that was replaced/stubbed with testdouble. In those cases, the
td.when
definition does not match as expected, causing the test to fail since thetheReturn
orthenResolve
does not happen as intended.In one project that is blocked by this, you can see that i converted the project from using sinon to testdouble in this commit and all of the project verification was still passing. Afterward, I converted the project to
"type"="module"
and updated the project to match. However, there are several cases where the inability to match passed functions causes unit test failures.Issue
from my investigation, it appears that the module that is not replaced by testdouble is still impacted in some way, causing it to have a different identity between the test and source files. because of this, the
td.when
fails to match what should be the same argument between the test and the source implementation.It isn't entirely clear to me how the loader is working to be confident, but this seems likely to be related to #492. If that is the case and you already have the information you need, feel free to close as a duplicate. Maybe my minimal reproduction repository below can still be helpful narrowing something down further?
Environment
node -v
output:v16.16.0
npm -v
(oryarn --version
) output:8.11.0
npm ls testdouble
(oryarn list testdouble
) version:Example Repo
npm it
and observe the issuehttps://github.com/travi-test/testdouble-esm-repro
The text was updated successfully, but these errors were encountered: