-
-
Notifications
You must be signed in to change notification settings - Fork 769
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
Elaborate on "For the stubbing to work, the stubbed method cannot be destructured, neither in the module under test nor in the test." #2552
Comments
Hi, @DanKaplanSES . I totally get that this is confusing. I have gone into depth on StackOverflow in explaining this a couple of times, one of which is this answer. That should answer most questions you would have. I could end it here, but maybe you - based on that - could suggest some rewording and/or example yourself, pushing a PR with the edited text? I am somewhat non-neutral about what I think of the text 😉 |
Not in the test, because how would you modify the export of the dependency without an object to modify the export on? BUT there's a catch All in all, this subject validates an update in this day and age, as the rules of the game have changed a bit with ESM. Regarding this:
I am not sure how you can destructure an import in the SUT and have Sinon's modification to the dependency take effect in the SUT. Some actual code showing what you think is false would go a long way. Explaining this was way easier in the world of CJS 😓 |
Hi @fatso83 , Thanks for the reply. I should've mentioned I'm writing typescript that transpiles into "esnext". Here's an example project: https://stackblitz.com/edit/typescript-svngnu?file=mytest.spec.ts You can't run the tests, but if you look at files The docs say, "...neither in the module under test nor in the test," but isn't this an example of destructuring in the module? I'd love to submit a PR after I understand this detail. |
Hi, that example is not really runnable, as you assume different things in the test and the SUT. In the b.ts module you expose an object as export It's hard to discuss non-runnable code, as it makes what we are talking about ambiguous. Anyway, if you use modules like P.S. Please do read the answer I linked to. It should clarify some things. |
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward? This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
@DanKaplanSES I just wonder if I could help this move? Did you figure out what you wanted to clarify? Not sure if I just made everything more confusing 🙈 P.S. I wrote an elaborate guide on various strategies for replacing dependencies in real-world projects using a typical bundler and transpilation steps. You might want to check it out: https://sinonjs.org/how-to/typescript-swc/ |
Hi @fatso83 Apologies for being so unresponsive. I've read the StackOverflow post but I haven't read your blog article yet (but will). In this thread, I think this is the crux of the issue:
It sounds like I think the documentation is saying one thing but it's really saying another. Before I continue, here's the documentation again with a smaller portion emphasized:
If that emphasized portion isn't referring to something like If the documentation cut out the emphasized part, I wouldn't be confused, because I know what that's referring to and I've experienced it firsthand:
So, to summarize, I feel like I know how to use sinon correctly, I just don't understand this tiny part of the documentation. Thanks! |
Is your feature request related to a problem? Please describe.
The How to stub a dependency of a module documentation says:
I'm not really sure what this bold part means. Does it mean you can't destructure the
import
statement? If so, while I have found that to be true in the test file, I haven't found that the be true in the module under test. That makes me think I'm either:Describe the solution you'd like
I'd like this sentence to be rewritten or expanded upon to clarify. If possible, an example would go a long way.
Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered: