Skip to content

Commit

Permalink
fix(types): fix test.each and describe.each types (#1653)
Browse files Browse the repository at this point in the history
  • Loading branch information
Demivan committed Jul 16, 2022
1 parent 5d9b03f commit daf9886
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 23 deletions.
20 changes: 12 additions & 8 deletions packages/vitest/src/types/tasks.ts
Expand Up @@ -103,24 +103,28 @@ interface EachFunction {
) => void
}

export type TestAPI<ExtraContext = {}> = ChainableFunction<
type ChainableTestAPI<ExtraContext = {}> = ChainableFunction<
'concurrent' | 'only' | 'skip' | 'todo' | 'fails',
[name: string, fn?: TestFunction<ExtraContext>, timeout?: number],
void
> & {
>

export type TestAPI<ExtraContext = {}> = ChainableTestAPI<ExtraContext> & {
each: EachFunction
skipIf(condition: any): TestAPI<ExtraContext>
runIf(condition: any): TestAPI<ExtraContext>
skipIf(condition: any): ChainableTestAPI<ExtraContext>
runIf(condition: any): ChainableTestAPI<ExtraContext>
}

export type SuiteAPI<ExtraContext = {}> = ChainableFunction<
type ChainableSuiteAPI<ExtraContext = {}> = ChainableFunction<
'concurrent' | 'only' | 'skip' | 'todo' | 'shuffle',
[name: string, factory?: SuiteFactory],
SuiteCollector<ExtraContext>
> & {
>

export type SuiteAPI<ExtraContext = {}> = ChainableSuiteAPI & {
each: EachFunction
skipIf(condition: any): SuiteAPI<ExtraContext>
runIf(condition: any): SuiteAPI<ExtraContext>
skipIf(condition: any): ChainableSuiteAPI<ExtraContext>
runIf(condition: any): ChainableSuiteAPI<ExtraContext>
}

export type HookListener<T extends any[], Return = void> = (...args: T) => Awaitable<Return>
Expand Down
15 changes: 0 additions & 15 deletions test/core/test/basic.test.ts
Expand Up @@ -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)
})
31 changes: 31 additions & 0 deletions 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)
})
*/
})

0 comments on commit daf9886

Please sign in to comment.