[mini.test] testing async functions #1107
-
Hi, I recently started tinkering with writing plugins, and even more recently started using mini.test I wonder what is the best approach for testing async functions with mini.test (in a child process)? One option I see is to make the async function print the result and then capture it with I'm probably missing an obvious solution due to my unfamiliarity. I would love your advice on the best approach. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
This very much depends on the tested function. If the problem here is to test a function which executes not immediately and can take unknown beforehand amount of time to finish, then the most straightforward approach is to wait some amount of time before checking the state of the child process. This is how I usually go with it. Here is an example from 'mini.test' test. Choosing an actual time to wait is tricky: should be long enough to have small number of false negatives but not long enough to unnecessarily prolong test execution. The other situation is if async function is meant to do something in a known amount of time (like show completion in 300 ms). Then the approach is similar but I also like to test if there is no side effect just before time expires. There are many examples in 'mini.nvim' tests, here is the first that came to mind. Hope it helps. If there any other questions, feel free to ask. |
Beta Was this translation helpful? Give feedback.
This very much depends on the tested function.
If the problem here is to test a function which executes not immediately and can take unknown beforehand amount of time to finish, then the most straightforward approach is to wait some amount of time before checking the state of the child process. This is how I usually go with it. Here is an example from 'mini.test' test. Choosing an actual time to wait is tricky: should be long enough to have small number of false negatives but not long enough to unnecessarily prolong test execution.
The other situation is if async function is meant to do something in a known amount of time (like show completion in 300 ms). Then the approach is similar but …