fix: reject calling suite function inside test (#9198)

This commit is contained in:
Hiroshi Ogawa 2025-12-08 17:48:41 +09:00 committed by GitHub
parent f72ed51e9d
commit 1a259c3403
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -538,6 +538,12 @@ function createSuite() {
factoryOrOptions?: SuiteFactory | TestOptions,
optionsOrFactory?: number | SuiteFactory,
) {
if (getCurrentTest()) {
throw new Error(
'Calling the suite function inside test function is not allowed. It can be only called at the top level or inside another suite function.',
)
}
let mode: RunMode = this.only
? 'only'
: this.skip

View File

@ -25,3 +25,9 @@ describe('a', () => {
it('visited', () => {
expect(visited).toBe(true)
})
it('suite inside test should throw', () => {
expect(() => {
describe('inside test', () => {})
}).toThrowErrorMatchingInlineSnapshot(`[Error: Calling the suite function inside test function is not allowed. It can be only called at the top level or inside another suite function.]`)
})