Skip to content

Nested test suite within a test case should return in an Error #9196

@Jason-eCargo

Description

@Jason-eCargo

Describe the bug

When there exists a test suite nested inside a test case the test suite is not enumerated, while this appears to be the correct behaviour it would be great if an error can be raised.

When there is a test case nested within a test case Vitest would throw an error: "Calling the test function inside another test function is not allowed. Please put it inside "describe" or "suite" so it can be properly collected."

Given that Vitest can detect the nested test case scenario it should also be able to detect that a test suite is nested within a test case and take appropriate action, whether that is throwing an error or permit the enumeration and running of the nested test suite(s).

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-ih2b3k6q

System Info

System:
  OS: Windows 11 10.0.22631
  CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor            
  Memory: 27.99 GB / 63.94 GB
Binaries:
  Node: 24.11.0
  Yarn: 1.22.22
  npm: Using node version:
    v24.11.0
    11.6.1
Browsers:
  Chrome: 143.0.7499.40
  Edge: Spartan
  Firefox: 145.0.2
  Internet Explorer: 11.0.22621.3527
npmPackages:
  @vitejs/plugin-react: ^4.4.1 => 4.4.1 
  @vitest/eslint-plugin: ^1.2.0 => 1.2.0 
  vite: ^6.3.5 => 6.3.5 
  vitest: ^4.0.15 => 4.0.15

Used Package Manager

npm

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    p3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions