Retain spy function names and fix spy.named(name) #1987
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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