the letter after invokeBefore or invokeAfter is now upper case for the naming convention,
but since we added a possibility to change the name, in many cases the upper case letter would look wrong.
and we should add possibility to disable that
example
before
classUser{sayHi(){}// we should write the first letter after "invokeBeforeName" as an upper case letter._SayHi(){}}User=invokeMeWrapper(User,{invokeBeforeName: '_'})
after
classUser{sayHi(){}// after we disabled it, we can write the same name as the original method_sayHi(){}}User=invokeMeWrapper(User,{invokeBeforeName: '_',disableCamelCase: true})
it should allow developers to specify some functionally to run every time a method get called
example:
classUser{invokeAfter(){console.log('I will be here every time, after any method get called')}invokeBefore(){console.log('I will be here every time, before any method get called')}sayHi(){console.log('hi')}sayGoodBye(){console.log('goodbye')}}constWrapperUser=invokeMeWrapper(User)constdev=newWrapperUser()dev.sayHi()dev.sayGoodBye()// I will be here every time, before any method get called// hi// I will be here every time, after any method get called// I will be here every time, before any method get called// goodbye// I will be here every time, after any method get called
classUser{sayHi(){console.log('saying hi')}_SayHi(){// should invoke after 'sayHi' method, since we choose '_' for 'invokeAfter' }$SayHi(){// should invoke before 'sayHi' method, since we choose '$' for 'invokeBefore' }}
(1) - index.test.ts file has test cases when it tests if a method is invoked or not by using js.fn, but it's better to convert it to jest.spyOn because this the right usage of it. and it will be good in (2)
(2) - use describe.each since all tests are almost the same
Is your feature request related to a problem? Please describe.
A good usage of invokeBefore is validations, but it's hard to do it, since I can't stop the functions from running by invoking a function or returning a specific value
Describe the solution you'd like
A callback passed to invokeBefore, that when invoked it stops the function from going to the original method.
invokeBeforeCreateUser(name,next){if(!name){// this should throw an error, stops the hook from going to the target method. next(newError('please enter your name'))}// this should pass the control to the target methodnext()}
Describe alternatives you've considered
None Additional context
None