mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-16 11:02:11 +08:00
Merge pull request #26603 from Miklet/feature/jest_each
[jest] Definitions for jest's each function
This commit is contained in:
10
types/jest/index.d.ts
vendored
10
types/jest/index.d.ts
vendored
@@ -209,6 +209,14 @@ declare namespace jest {
|
||||
readonly name: string;
|
||||
}
|
||||
|
||||
interface Each {
|
||||
(cases: any[]): (name: string, fn: (...args: any[]) => any) => void;
|
||||
(strings: TemplateStringsArray, ...placeholders: any[]): (
|
||||
name: string,
|
||||
fn: (arg: any) => any
|
||||
) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test closure
|
||||
*/
|
||||
@@ -227,6 +235,7 @@ declare namespace jest {
|
||||
only: It;
|
||||
skip: It;
|
||||
concurrent: It;
|
||||
each: Each;
|
||||
}
|
||||
|
||||
interface Describe {
|
||||
@@ -234,6 +243,7 @@ declare namespace jest {
|
||||
(name: number | string | Function | FunctionLike, fn: EmptyFunction): void;
|
||||
only: Describe;
|
||||
skip: Describe;
|
||||
each: Each;
|
||||
}
|
||||
|
||||
interface MatcherUtils {
|
||||
|
||||
@@ -956,3 +956,103 @@ const testJestConfig = (defaults: jest.DefaultOptions) => {
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/26368
|
||||
|
||||
describe.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
|
||||
".add(%i, %i)",
|
||||
(a: number, b: number, expected: number) => {
|
||||
test(`returns ${expected}`, () => {
|
||||
expect(a + b).toBe(expected);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
interface Case {
|
||||
a: number;
|
||||
b: number;
|
||||
expected: number;
|
||||
}
|
||||
|
||||
describe.each`
|
||||
a | b | expected
|
||||
${1} | ${1} | ${2}
|
||||
${1} | ${2} | ${3}
|
||||
${2} | ${1} | ${3}
|
||||
`("$a + $b", ({ a, b, expected }: Case) => {
|
||||
test(`returns ${expected}`, () => {
|
||||
expect(a + b).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe.only.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
|
||||
".add(%i, %i)",
|
||||
(a, b, expected) => {
|
||||
test(`returns ${expected}`, () => {
|
||||
expect(a + b).toBe(expected);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
describe.only.each`
|
||||
a | b | expected
|
||||
${1} | ${1} | ${2}
|
||||
${1} | ${2} | ${3}
|
||||
${2} | ${1} | ${3}
|
||||
`("$a + $b", ({ a, b, expected }: Case) => {
|
||||
test(`returns ${expected}`, () => {
|
||||
expect(a + b).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
|
||||
".add(%i, %i)",
|
||||
(a, b, expected) => {
|
||||
test(`returns ${expected}`, () => {
|
||||
expect(a + b).toBe(expected);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
describe.skip.each`
|
||||
a | b | expected
|
||||
${1} | ${1} | ${2}
|
||||
${1} | ${2} | ${3}
|
||||
${2} | ${1} | ${3}
|
||||
`("$a + $b", ({ a, b, expected }: Case) => {
|
||||
test(`returns ${expected}`, () => {
|
||||
expect(a + b).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
test.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
|
||||
".add(%i, %i)",
|
||||
(a, b, expected) => {
|
||||
expect(a + b).toBe(expected);
|
||||
}
|
||||
);
|
||||
|
||||
test.each`
|
||||
a | b | expected
|
||||
${1} | ${1} | ${2}
|
||||
${1} | ${2} | ${3}
|
||||
${2} | ${1} | ${3}
|
||||
`("returns $expected when $a is added $b", ({ a, b, expected }: Case) => {
|
||||
expect(a + b).toBe(expected);
|
||||
});
|
||||
|
||||
test.only.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
|
||||
".add(%i, %i)",
|
||||
(a, b, expected) => {
|
||||
expect(a + b).toBe(expected);
|
||||
}
|
||||
);
|
||||
|
||||
test.only.each`
|
||||
a | b | expected
|
||||
${1} | ${1} | ${2}
|
||||
${1} | ${2} | ${3}
|
||||
${2} | ${1} | ${3}
|
||||
`("returns $expected when $a is added $b", ({ a, b, expected }: Case) => {
|
||||
expect(a + b).toBe(expected);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user