Skip to content

Commit

Permalink
馃 Merge PR #63882 [jest] type done callback on each by @staff0rd
Browse files Browse the repository at this point in the history
* [jest] type done callback on each

* additional test case

* remove typing from array of arrays
  • Loading branch information
staff0rd committed Mar 15, 2023
1 parent d7dade7 commit 6439217
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions types/jest/index.d.ts
Expand Up @@ -486,15 +486,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 @@ -1675,6 +1675,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 @@ -1686,9 +1697,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 @@ -1754,6 +1766,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) => {
// $ExpectType ["a", "b", "ab"] | ["d", 2, "d2"]
Expand Down

0 comments on commit 6439217

Please sign in to comment.