mirror of
https://github.com/vitest-dev/vitest.git
synced 2025-12-08 18:26:03 +00:00
fix: reject calling suite function inside test (#9198)
This commit is contained in:
parent
f72ed51e9d
commit
1a259c3403
@ -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
|
||||
|
||||
@ -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.]`)
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user