uncino
uncino copied to clipboard
Write better tests for the library
Currently the tests included only check for quite trivial behaviours but don't really guarantee the correctness of the original code in various aspects.
Additional tests are needed to check:
- The functions passed as hooks are what is actually being called when running the hook. This should involve creating some mock or stub functions and then checking that they have been called with some assertion. As they currently are written most tests would pass even if
runHooksimply returned the passed argument plus 3 ignoring everything else. - That actions actually run. Currently the tests only verify that actions are stored and that
runActionresolves but they don't check anything at all about the actions actually being executed. Again, some mocks should be setup and used to verify that they have actually been called. - That the "
priority" argument works. Currently there's no test at all that verifies in any way the order/priority in which the functions are called. This applies to both hooks and actions. - A number of additional edge cases. It would be useful to have tests that check things like calling
runHookwith no hooks added, or callingremoveHookwhen no hook has been added, or removing/adding hooks from inside a hook function (what is the expected behaviour here? is it documented anywhere?), or some other similar infrequent but not unthinkable cases.
Note that all these things are probably correct in the code now. I'm not saying there are any errors right now, but I'm also not saying that there aren't. What I'm saying is that the included tests are too weak to be useful for anything; they offer very little or no safety at all.
Hi @gezeta-id I will try shortly to add the tests you have listed above, if you like you can also participate in the writing with a pull request :)