diff --git a/packages/vitest/src/types/tasks.ts b/packages/vitest/src/types/tasks.ts index 773601590d78..1f4c876288aa 100644 --- a/packages/vitest/src/types/tasks.ts +++ b/packages/vitest/src/types/tasks.ts @@ -103,24 +103,28 @@ interface EachFunction { ) => void } -export type TestAPI = ChainableFunction< +type ChainableTestAPI = ChainableFunction< 'concurrent' | 'only' | 'skip' | 'todo' | 'fails', [name: string, fn?: TestFunction, timeout?: number], void -> & { +> + +export type TestAPI = ChainableTestAPI & { each: EachFunction - skipIf(condition: any): TestAPI - runIf(condition: any): TestAPI + skipIf(condition: any): ChainableTestAPI + runIf(condition: any): ChainableTestAPI } -export type SuiteAPI = ChainableFunction< +type ChainableSuiteAPI = ChainableFunction< 'concurrent' | 'only' | 'skip' | 'todo' | 'shuffle', [name: string, factory?: SuiteFactory], SuiteCollector -> & { +> + +export type SuiteAPI = ChainableSuiteAPI & { each: EachFunction - skipIf(condition: any): SuiteAPI - runIf(condition: any): SuiteAPI + skipIf(condition: any): ChainableSuiteAPI + runIf(condition: any): ChainableSuiteAPI } export type HookListener = (...args: T) => Awaitable diff --git a/test/core/test/basic.test.ts b/test/core/test/basic.test.ts index 122397d10b91..61e488ee07e9 100644 --- a/test/core/test/basic.test.ts +++ b/test/core/test/basic.test.ts @@ -57,18 +57,3 @@ it('timeout', () => new Promise(resolve => setTimeout(resolve, timeout))) it.fails('deprecated done callback', (done) => { done() }) - -const shouldSkip = true - -it.skipIf(shouldSkip)('skipped', () => { - throw new Error('foo') -}) -it.skipIf(!shouldSkip)('not skipped', () => { - expect(1).toBe(1) -}) -it.runIf(!shouldSkip)('skipped 2', () => { - throw new Error('foo') -}) -it.runIf(shouldSkip)('not skipped 2', () => { - expect(1).toBe(1) -}) diff --git a/test/core/test/run-if.test.ts b/test/core/test/run-if.test.ts new file mode 100644 index 000000000000..1a67c4689bc7 --- /dev/null +++ b/test/core/test/run-if.test.ts @@ -0,0 +1,31 @@ +import { describe, expect, it } from 'vitest' + +describe('runIf', () => { + const shouldSkip = true + + it.skipIf(shouldSkip)('skipped', () => { + throw new Error('foo') + }) + + it.skipIf(!shouldSkip)('not skipped', () => { + expect(1).toBe(1) + }) + + it.runIf(!shouldSkip)('skipped 2', () => { + throw new Error('foo') + }) + + it.runIf(shouldSkip)('not skipped 2', () => { + expect(1).toBe(1) + }) + + /* + it.runIf(!shouldSkip).each([1, 2, 3])('works with each skipped', (num) => { + expect(Number.isInteger(num)).toBe(true) + }) + + it.runIf(shouldSkip).each([1, 2, 3])('works with each not skipped', (num) => { + expect(Number.isInteger(num)).toBe(true) + }) + */ +})