[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

chore(runner): update better error message for nested test (#4652)

Co-authored-by: Vladimir Sheremet <sleuths.slews0s@icloud.com>

authored by

Dunqing
Vladimir Sheremet
and committed by
GitHub
(Jan 3, 2024, 7:00 PM +0100) 1efc29b6 7b4a2fce

+6 -6
+1 -1
packages/runner/src/suite.ts
··· 13 13 export const test = createTest( 14 14 function (name: string | Function, fn?: TestFunction, options?: number | TestOptions) { 15 15 if (getCurrentTest()) 16 - throw new Error('Nested tests are not allowed') 16 + throw new 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.') 17 17 18 18 getCurrentSuite().test.fn.call(this, formatName(name), fn, options) 19 19 },
+5 -5
test/core/test/nested-test.test.ts
··· 3 3 test('nested test should throw error', () => { 4 4 expect(() => { 5 5 test('test inside test', () => {}) 6 - }).toThrowErrorMatchingInlineSnapshot(`[Error: Nested tests are not allowed]`) 6 + }).toThrowErrorMatchingInlineSnapshot(`[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.]`) 7 7 8 8 expect(() => { 9 9 test.each([1, 2, 3])('test.each inside test %d', () => {}) 10 - }).toThrowErrorMatchingInlineSnapshot(`[Error: Nested tests are not allowed]`) 10 + }).toThrowErrorMatchingInlineSnapshot(`[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.]`) 11 11 12 12 expect(() => { 13 13 test.skipIf(false)('test.skipIf inside test', () => {}) 14 - }).toThrowErrorMatchingInlineSnapshot(`[Error: Nested tests are not allowed]`) 14 + }).toThrowErrorMatchingInlineSnapshot(`[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.]`) 15 15 }) 16 16 17 17 describe('parallel tests', () => { 18 18 test.concurrent('parallel test 1 with nested test', () => { 19 19 expect(() => { 20 20 test('test inside test', () => {}) 21 - }).toThrowErrorMatchingInlineSnapshot(`[Error: Nested tests are not allowed]`) 21 + }).toThrowErrorMatchingInlineSnapshot(`[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.]`) 22 22 }) 23 23 test.concurrent('parallel test 2 without nested test', () => {}) 24 24 test.concurrent('parallel test 3 without nested test', () => {}) 25 25 test.concurrent('parallel test 4 with nested test', () => { 26 26 expect(() => { 27 27 test('test inside test', () => {}) 28 - }).toThrowErrorMatchingInlineSnapshot(`[Error: Nested tests are not allowed]`) 28 + }).toThrowErrorMatchingInlineSnapshot(`[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.]`) 29 29 }) 30 30 })