From 29ee8be78f48228b595b9902fa2b76ef9ca4b614 Mon Sep 17 00:00:00 2001 From: Dunqing Date: Fri, 6 Oct 2023 07:35:03 +0800 Subject: [PATCH] test: add test case for test without describe --- test/core/test/test-extend.test.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/core/test/test-extend.test.ts b/test/core/test/test-extend.test.ts index 9ec917cfc3ba..85d3c232393a 100644 --- a/test/core/test/test-extend.test.ts +++ b/test/core/test/test-extend.test.ts @@ -303,3 +303,26 @@ describe('test.extend()', () => { }) }) }) + +// test extend with top level test +const numbers: number[] = [] +const teardownFn = vi.fn() +const teardownTest = test.extend<{ + numbers: number[] +}>({ + numbers: async ({}, use) => { + numbers.push(1, 2, 3) + await use(numbers) + numbers.splice(0, numbers.length) + teardownFn() + }, +}) + +teardownTest('test without describe', ({ numbers }) => { + expect(numbers).toHaveLength(3) +}) + +test('teardown should be called once time', () => { + expect(numbers).toHaveLength(0) + expect(teardownFn).toBeCalledTimes(1) +})