Skip to content
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

Write better tests for the library #2

Open
gezeta-id opened this issue Aug 31, 2022 · 1 comment
Open

Write better tests for the library #2

gezeta-id opened this issue Aug 31, 2022 · 1 comment

Comments

@gezeta-id
Copy link

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 runHook simply returned the passed argument plus 3 ignoring everything else.
  • That actions actually run. Currently the tests only verify that actions are stored and that runAction resolves 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 runHook with no hooks added, or calling removeHook when 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.

@riktar
Copy link
Owner

riktar commented Aug 31, 2022

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants