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
Retain spy function names and fix spy.named(name) #1987
Conversation
Pull Request Test Coverage Report for Build 2811
💛 - Coveralls |
@@ -152,6 +152,12 @@ function createProxy(func, proxyLength) { | |||
return p.invoke(func, this, slice(arguments)); | |||
}; | |||
} | |||
var nameDescriptor = Object.getOwnPropertyDescriptor(func, "name"); |
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 code in this change looks very similar to the code in the next change. Would it be wise to extract it to a shared function? Perhaps even put that function in @sinonjs/commons
?
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.
Yes, I had the same thought, but in one case we're just using one descriptor as is, in the other case we modfy the value
. Extracting a function produces more code and would include a superfluous value
assignment for one of the cases. So I decided against it for clarity.
I am treating commons
as a toolbelt for shared functions. This is a Sinon only feature so far. We can move it if we want to reuse it elsewhere.
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.
THUNDERBIRDS ARE GO!
Released in |
Purpose (TL;DR) - mandatory
name
as the function they wrapname
property inspy.named(name)
, not just thedisplayName
(used for sinon error messages)Fixes #250
Background (Problem in detail)
We used to retain the name of spied functions, but this has been lost along the way at some point.
There is #950 which shows in the issue description that the
name
property of a spy reflected the original function name. However, the test that is verifying this was added later and it hard coded the name to"proxy"
.I think this dates back to the old times when we used
eval
to generate the spy function.Solution - optional
This change verifies that a
name
can be configured on the function – unfortunately this is inconsistent across (old but supported) browser versions – and then configures the name using the same property descritor flags as the original value.How to verify - mandatory
npm install
npm test
npm run test-cloud
Checklist for author
npm run lint
passes