Skip to content

Commit 1a259c3

Browse files
authored
fix: reject calling suite function inside test (#9198)
1 parent f72ed51 commit 1a259c3

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

packages/runner/src/suite.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,12 @@ function createSuite() {
538538
factoryOrOptions?: SuiteFactory | TestOptions,
539539
optionsOrFactory?: number | SuiteFactory,
540540
) {
541+
if (getCurrentTest()) {
542+
throw new Error(
543+
'Calling the suite function inside test function is not allowed. It can be only called at the top level or inside another suite function.',
544+
)
545+
}
546+
541547
let mode: RunMode = this.only
542548
? 'only'
543549
: this.skip

test/core/test/nested-suite.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ describe('a', () => {
2525
it('visited', () => {
2626
expect(visited).toBe(true)
2727
})
28+
29+
it('suite inside test should throw', () => {
30+
expect(() => {
31+
describe('inside test', () => {})
32+
}).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.]`)
33+
})

0 commit comments

Comments
 (0)