Skip to content
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

Improve error message given when a property is only exposed as a getter #2531

Closed
fatso83 opened this issue Aug 7, 2023 · 3 comments
Closed
Labels
Cannot reproduce For issues we are unable to reproduce. Difficulty: Easy Documentation Feature Request Property accessors Property Getters/Setters semver:patch changes will cause a new patch version

Comments

@fatso83
Copy link
Contributor

fatso83 commented Aug 7, 2023

Is your feature request related to a problem? Please describe.

Confusion arises when module exports are not transpiled into an expected form . Typically you expect module.myExport = stub() to make sense, but if myExport is really just a getter you will not be able to assign to that prop. See #2530

Describe the solution you'd like
We should try to detect such cases and give some more meaningful error message, given the context. We could have some elaboration on our homepage and then link to that in the error message.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

if trying to to wrap an undefined property; then
   if property name has a getter; then
        output hint that the property `propName` is undefined, but it is defined as a getter, so you might want to try `sandbox.stub(obj, propName).get(() => customStub)`
  else 
       output a generic error about undefined property
  endif
endif

Additional context
See #2530

@ahmed1hsn
Copy link

@fatso83 how we can reproduce this issue? and alternatively, how can we find out that property is getter or setter if it's undefined at first place?

@fatso83
Copy link
Contributor Author

fatso83 commented Aug 13, 2023

@ahmed1hsn You are correct in pointing this out! This description is both wrong and it actually made me aware of a bug inside of Sinon. I had a look at the error message that was originally mentioned in #2530 to see what was really going on and found that it does a typeof wrappedMethod, and that will always be undefined as nothing has set that variable yet.

Skjermbilde 2023-08-13 kl  23 08 40

Additionally, as you point out, if something has a getter, it is defined. I must have been a bit sleep deprived when writing this initially. Adding an actual reproduction case (as I could not do that in 2530) is indeed the first step 😄 And the this issue needs updating.

@fatso83 fatso83 added the Cannot reproduce For issues we are unable to reproduce. label Aug 13, 2023
@fatso83
Copy link
Contributor Author

fatso83 commented Aug 13, 2023

This issue does not make sense as it is, being based on an issue we could not reproduce and having some faulty assumptions.

@fatso83 fatso83 closed this as completed Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cannot reproduce For issues we are unable to reproduce. Difficulty: Easy Documentation Feature Request Property accessors Property Getters/Setters semver:patch changes will cause a new patch version
Projects
None yet
Development

No branches or pull requests

2 participants