-
-
Notifications
You must be signed in to change notification settings - Fork 771
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
Fix spying on *etter methods #1205
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks good as it is. The only thing I find a bit missing are code comments that tell why things are done. To the casual reader, there is very little help in seeing why the descriptor
object is being introduced. I am assuming this is to avoid triggering the stubbed property? Could have been nice to see it commented.
On the other hand, this is just my opinion, and I am not sure the others agree. I just happen to like comments :-)
Sorry for the slow followup ... you are right about the failing build. Restarting the Travis build seems to have fixed the failing tests. |
@mroderick objections to merging this? I could like a little comment or two, other than that ... 👍 |
@fatso83 I made some comments while studying this code and doing the fix, but since the code didn't have any comments before I assumed those pieces of information would be considered unnecessary. Thanks for the feedback! |
@@ -2226,6 +2226,34 @@ | |||
|
|||
assert.equals(spy.length, 3); | |||
} | |||
}, | |||
|
|||
"etters": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the naming here. Either getters and setters
or a getters
section separate from the setters
section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right! It really looks better, thanks for the feedback. I'll do it.
@lucasfcosta, as long as comments document the intent, not the steps of the implementation, I think it usually helps the understanding of the reader. If you can add a small comment I think it would help future readers understanding the code. I also wasn't a fan of the "etters" naming, but it's not a big thing. Just change it per fearphage's comment and this should be good to merge. |
9060a4b
to
8dace57
Compare
Here it is! I made sure to add two concise comment lines explaining why we needed a new I also renamed both of those tests containing the Thanks for the feedback @fatso83 and @fearphage, let me know if I missed anything. |
Great work, and thanks for listening to the input. Much appreciated. |
Hi, Is there a migration path on how to implement this in the new Thanks a lot :) |
Hi @muuki88, this is only a fix for the v1.17 version. These are the docs on how to implement getter and setters spies and stubs:
|
Thanks a lot @lucasfcosta . This works for me. The confusing was due to the missing typescript definitions for the Should I open an issue for adding the type signatures to the |
} | ||
}, | ||
|
||
"it is possible to spy setters": function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation is off here. This should have the same indentation as the test above it and the preceding closing brace should be moved below this test.
Purpose (TL;DR)
This PR aims to fix #1018 on
v1.17
.Basically I just needed to pass a new descriptor with only the property from the propDescriptor which is going to be spied on.
I also added tests to prove both stubbing and spying work as @mroderick did on the issue itself.
Background (Problem in detail)
The problem happened because the property descriptor being passed to be spied on had non-function property values (because it was a complete property descriptor taken from that property) and then that caused an error.
Solution
As I've said above I just needed to passa a property descriptor with only the property which was going to be spied instead of the whole property descriptor
How to verify
npm install
npm run test
-> This will run the new tests I've addedThanks for the awesome work you have been doing on Sinon, I'm looking forward to contribute more with you, please let me know if you need anything!
I've read the contribution guidelines but I'm not sure this PR meets your commit/coding patterns, please let me know if I've done anything wrong or missed anything and I'll happily fix it. You rock ❤️
EDIT: The build seems to be failing on CI for an unknown reason. I've read the log and I think it might be related to Travis itself and not this PR. Do you have any idea why this is happening?