Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jest] type done callback on each #63882

Merged
merged 3 commits into from Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions types/jest/index.d.ts
Expand Up @@ -494,7 +494,7 @@ declare namespace jest {
// Exclusively arrays.
<T extends any[] | [any]>(cases: ReadonlyArray<T>): (
name: string,
fn: (...args: T) => any,
fn: (...t: [...args: T, done: DoneCallback]) => any,
timeout?: number,
) => void;
<T extends ReadonlyArray<any>>(cases: ReadonlyArray<T>): (
Expand All @@ -503,15 +503,15 @@ declare namespace jest {
timeout?: number,
) => void;
// Not arrays.
<T>(cases: ReadonlyArray<T>): (name: string, fn: (...args: T[]) => any, timeout?: number) => void;
<T>(cases: ReadonlyArray<T>): (name: string, fn: (arg: T, done: DoneCallback) => any, timeout?: number) => void;
(cases: ReadonlyArray<ReadonlyArray<any>>): (
name: string,
fn: (...args: any[]) => any,
timeout?: number,
) => void;
(strings: TemplateStringsArray, ...placeholders: any[]): (
name: string,
fn: (arg: any) => any,
fn: (arg: any, done: DoneCallback) => any,
timeout?: number,
) => void;
}
Expand Down
20 changes: 17 additions & 3 deletions types/jest/jest-tests.ts
Expand Up @@ -1646,12 +1646,24 @@ describe.each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
])('.add(%i, %i)', (a: number, b: number, expected: number) => {
])('.add(%i, %i)', (a: number, b: number, expected: number, done) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected);
done();
});
});

// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34617

it.each<number>([1, 2, 3])('dummy: %d', (num, done) => {
done();
});

const casesReadonlyArray = [[1, 2, 3] as ReadonlyArray<number>] as ReadonlyArray<ReadonlyArray<number>>;
it.each(casesReadonlyArray)('%d', (a, b, c) => {
expect(a + b).toBe(c);
});

interface Case {
a: number;
b: number;
Expand All @@ -1663,9 +1675,10 @@ describe.each`
${1} | ${1} | ${2}
${1} | ${2} | ${3}
${2} | ${1} | ${3}
`('$a + $b', ({ a, b, expected }: Case) => {
`('$a + $b', ({ a, b, expected }: Case, done) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected);
done();
});
});

Expand Down Expand Up @@ -1774,9 +1787,10 @@ test.each`
test.each([
[1, '1'],
[2, '2'],
])('', (a, b) => {
])('', (a, b, done) => {
a; // $ExpectType number
b; // $ExpectType string
done; // $ExpectType DoneCallback
});

test.only.each([
Expand Down