Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Bad Hook API Design: Hooks are inconsistent and impure functions #288
Some hooks have inconsistent return values and are impure:
This makes hook composition harder than it needs to be:
In my case, I was writing a hook that would restrict to roles OR owner.
Yes, I think @ekryski agrees that at least all built in hooks should always return a Promise (although they do resolve asynchronously which might not always end up being the same as synchronous hooks).
I'm not sure about the
I'm still trying to understand the use case where it is necessary to mock and test the built-in authentication hooks since we are already testing them here (and if test cases are missing we should add them to our test suite). Ideally in an application setup you can just test if the actual service calls behave as expected.
Yup definitely agree. That's been bothering me for a while. Currently in the process of rewriting them to always return promises.
I think that's a good idea. Using
Did I say anything about testing?
Anyway, there are many reasons to test the build in hooks:
Granted, last two are more integration than unit tests, but still nice to have.
The 'this' comment is perhaps a matter of personal preference. I just don't like using "hook.call(service,arg)"