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 all commits
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
4 changes: 2 additions & 2 deletions types/jest/index.d.ts
Expand Up @@ -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
24 changes: 23 additions & 1 deletion types/jest/jest-tests.ts
Expand Up @@ -1652,6 +1652,17 @@ describe.each([
});
});

// 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 +1674,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 @@ -1731,6 +1743,16 @@ test.each([
5000,
);

test.each([
[
{ prop1: true, prop2: true },
{ prop1: true, prop2: true },
],
[{ prop1: true }, { prop1: true, prop2: false }],
])('%j -> %j', (input, output) => {
console.log(input, output);
});

declare const constCases: [['a', 'b', 'ab'], ['d', 2, 'd2']];
test.each(constCases)('%s + %s', (...args) => {
// following assertion is skipped because of flaky testing
Expand Down