Skip to content

Commit

Permalink
fix: types for EachFunction are missing awaitable return (fix: #1181) (
Browse files Browse the repository at this point in the history
  • Loading branch information
bissolli committed Apr 22, 2022
1 parent a82b6b1 commit 95b1ba4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/vitest/src/types/tasks.ts
Expand Up @@ -86,15 +86,15 @@ type ExtractEachCallbackArgs<T extends ReadonlyArray<any>> = {
interface EachFunction {
<T extends any[] | [any]>(cases: ReadonlyArray<T>): (
name: string,
fn: (...args: T) => void
fn: (...args: T) => Awaitable<void>
) => void
<T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (
name: string,
fn: (...args: ExtractEachCallbackArgs<T>) => void
fn: (...args: ExtractEachCallbackArgs<T>) => Awaitable<void>
) => void
<T>(cases: ReadonlyArray<T>): (
name: string,
fn: (...args: T[]) => void
fn: (...args: T[]) => Awaitable<void>
) => void
}

Expand Down
14 changes: 14 additions & 0 deletions test/core/test/each.test.ts
Expand Up @@ -83,3 +83,17 @@ test.each([
])('the index of the test case is %#', (a, b, expected) => {
expect(a + b).toBe(expected)
})

test.each([
[1, 2, 3],
[4, 5, 9],
])('return a promise like result %#', async(a, b, expected) => {
const promiseResolver = (first: number, second: number) => {
return new Promise((resolve) => {
setTimeout(() => resolve(first + second), 1)
})
}

const result = await promiseResolver(a, b)
expect(result).toBe(expected)
})

0 comments on commit 95b1ba4

Please sign in to comment.