From 1efc29b6690acf81f674a7c355d24aea5cb670f3 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Thu, 4 Jan 2024 02:00:58 +0800 Subject: [PATCH] chore(runner): update better error message for nested test (#4652) Co-authored-by: Vladimir Sheremet --- packages/runner/src/suite.ts | 2 +- test/core/test/nested-test.test.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/runner/src/suite.ts b/packages/runner/src/suite.ts index dbec99b184b9..f4d197ddb121 100644 --- a/packages/runner/src/suite.ts +++ b/packages/runner/src/suite.ts @@ -13,7 +13,7 @@ export const suite = createSuite() export const test = createTest( function (name: string | Function, fn?: TestFunction, options?: number | TestOptions) { if (getCurrentTest()) - throw new Error('Nested tests are not allowed') + 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.') getCurrentSuite().test.fn.call(this, formatName(name), fn, options) }, diff --git a/test/core/test/nested-test.test.ts b/test/core/test/nested-test.test.ts index 23cf7d38d29a..b03cabffe8c7 100644 --- a/test/core/test/nested-test.test.ts +++ b/test/core/test/nested-test.test.ts @@ -3,28 +3,28 @@ import { describe, expect, test } from 'vitest' test('nested test should throw error', () => { expect(() => { test('test inside test', () => {}) - }).toThrowErrorMatchingInlineSnapshot(`[Error: Nested tests are not allowed]`) + }).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.]`) expect(() => { test.each([1, 2, 3])('test.each inside test %d', () => {}) - }).toThrowErrorMatchingInlineSnapshot(`[Error: Nested tests are not allowed]`) + }).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.]`) expect(() => { test.skipIf(false)('test.skipIf inside test', () => {}) - }).toThrowErrorMatchingInlineSnapshot(`[Error: Nested tests are not allowed]`) + }).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.]`) }) describe('parallel tests', () => { test.concurrent('parallel test 1 with nested test', () => { expect(() => { test('test inside test', () => {}) - }).toThrowErrorMatchingInlineSnapshot(`[Error: Nested tests are not allowed]`) + }).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.]`) }) test.concurrent('parallel test 2 without nested test', () => {}) test.concurrent('parallel test 3 without nested test', () => {}) test.concurrent('parallel test 4 with nested test', () => { expect(() => { test('test inside test', () => {}) - }).toThrowErrorMatchingInlineSnapshot(`[Error: Nested tests are not allowed]`) + }).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.]`) }) })