diff --git a/packages/runner/src/types/tasks.ts b/packages/runner/src/types/tasks.ts index c345d4622147..16f90c0b46c6 100644 --- a/packages/runner/src/types/tasks.ts +++ b/packages/runner/src/types/tasks.ts @@ -498,14 +498,14 @@ export type HookListener = ( ...args: T ) => Awaitable -export type HookCleanupCallback = (() => Awaitable) | void +export type HookCleanupCallback = (() => Awaitable) | any export interface BeforeAllListener { (suite: Readonly): Awaitable } export interface AfterAllListener { - (suite: Readonly): Awaitable + (suite: Readonly): Awaitable } export interface BeforeEachListener { @@ -519,7 +519,7 @@ export interface AfterEachListener { ( context: ExtendedContext & ExtraContext, suite: Readonly - ): Awaitable + ): Awaitable } export interface SuiteHooks { diff --git a/test/core/test/hooks.test.ts b/test/core/test/hooks.test.ts index d9df35c96335..5f2ceffedc81 100644 --- a/test/core/test/hooks.test.ts +++ b/test/core/test/hooks.test.ts @@ -1,4 +1,4 @@ -import { beforeAll, beforeEach, expect, it, suite } from 'vitest' +import { afterAll, afterEach, beforeAll, beforeEach, expect, it, suite } from 'vitest' let count = -1 @@ -80,4 +80,26 @@ suite('hooks cleanup', () => { it('end', () => { expect(cleanUpCount).toBe(0) }) + + suite('do nothing when given a non-function value as cleanupCallback', () => { + beforeAll(() => { + return 1 + }) + beforeEach(() => { + return null + }) + afterAll(() => { + return '1' + }) + afterEach(() => { + return {} + }) + + it('one', () => { + expect(cleanUpCount).toBe(0) + }) + }) + it('end', () => { + expect(cleanUpCount).toBe(0) + }) })