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

Runtime Warning or Error Message for Nested test() Functions #4229

Closed
4 tasks done
mrsekut opened this issue Oct 3, 2023 · 0 comments · Fixed by #4262
Closed
4 tasks done

Runtime Warning or Error Message for Nested test() Functions #4229

mrsekut opened this issue Oct 3, 2023 · 0 comments · Fixed by #4262
Labels
good first issue Good for newcomers p2-nice-to-have Not breaking anything but nice to have (priority) pr welcome

Comments

@mrsekut
Copy link

mrsekut commented Oct 3, 2023

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.

// Example of the issue:
describe('AAA', () => {
  test('aaaa', () => {
    expect(1).toBe(1); // pass. ok
    test('bbb', () => {
      expect(2).toBe(1); // pass?. Not executed in reality
    });
  });
})

Suggested solution

We could provide a runtime warning or error message whenever a test() function is nested within another test() function. This message should clearly indicate that the nested test() was not executed, preventing any misunderstanding or confusion on the part of the user. For instance, upon detecting a nested test(), 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.

// Additional example with `test.each`:
test('sum(a, b) returns the correct result', () => {
  const testData = [
    [1, 2, 3],
    [2, 3, 5],
  ];
  test.each(testData)('sum(%i, %i)', (a, b, expected) => {
    expect(sum(a, b)).toBe(expected);  // Not executed in reality
  });
});

test('another test case', () => {
  expect(1).toBe(1); // pass. ok
});

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

@sheremet-va sheremet-va added good first issue Good for newcomers pr welcome p2-nice-to-have Not breaking anything but nice to have (priority) labels Oct 3, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Good for newcomers p2-nice-to-have Not breaking anything but nice to have (priority) pr welcome
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants