-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
CallTracker
wrapper function to have original function length
#40484
Comments
@primeare Would you like to work on this? |
@Mesteery, yes, I do want to work on this feature implementation. Is there anything important or particular I should know prior to starting working on the implementation except accepting the Code of Conduct and reading the Contribution Guidelines? |
Hopefully documentation (such as in |
There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document. |
Sure, go for it :) |
PR-URL: nodejs/node#42909 Fixes: nodejs/node#40484 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Is your feature request related to a problem?
Some frameworks and libraries (ex. Express.js middleware execution) rely on the function length and use it to decide the appropriate behaviour.
Currently, the
CallTracker
Node.js API does not proxy the original function length. Thus, its application may be limited in certain circumstances.Such widely popular test automation frameworks as Jest have built-in functionality to match the arity of a function when it is mocked. And they also consider the original function length as a source of truth.
So here, it is proposed to change the
CallTracker.calls
wrapper function to match the arity of the original function.I would be glad to work on this feature and create my first code contribution to the Node.js codebase! 😃
Describe the solution you'd like
To achieve the goal of this feature request, it is proposed to change the
CallTracker.calls
wrapper function, and, for instance, redefine the length property of this function with:Moreover, the wrapper function may also be refactored to use rest parameters instead of the arguments object.
Describe alternatives you've considered
It is an open question whether it is required to proxy
call
,apply
andbind
methods calls to the original function, as well as to detect if the wrapper function is called as a constructor.The text was updated successfully, but these errors were encountered: