Runtime Warning or Error Message for Nested test() Functions #4229
Labels
good first issue
Good for newcomers
p2-nice-to-have
Not breaking anything but nice to have (priority)
pr welcome
Clear and concise description of the problem
As a developer using Vitest, I want to receive a runtime error or warning message for nested
test()
functions so that I can be immediately aware that the nested tests are not being executed. This feedback is crucial as, without it, there might be a misunderstanding that the nested tests are passing when they are not executed in reality.Suggested solution
We could provide a runtime warning or error message whenever a
test()
function is nested within anothertest()
function. This message should clearly indicate that the nestedtest()
was not executed, preventing any misunderstanding or confusion on the part of the user. For instance, upon detecting a nestedtest()
, the runtime could output a message like “Warning: Nested test() detected at [location]. Nested tests will not be executed.”Alternative
An alternative could be to include in the documentation clear and prominent warnings about the non-execution of nested
test()
functions, along with examples illustrating the potential confusion in the absence of runtime messages. However, this passive approach might not be as effective as providing immediate feedback through runtime messages.Additional context
The issue is particularly noticeable and problematic when using test.each since it is visually easy to accidentally nest test.each inside another test() due to similar indentation, leading to the silent non-execution of the nested tests without the user's knowledge.
Note on Prior Discussion
This issue has been previously discussed in the following discussion thread approximately six months ago. However, there has been no significant progress or resolution since then, prompting the creation of this formal issue for more visibility and action.
Validations
The text was updated successfully, but these errors were encountered: