iTranslated by AI
The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🗂
How to run the same test case with multiple values in Jest
When you want to run the same test case with multiple values in Jest
How to
Use jest.each
describe.each(table)(name, fn, timeout)test.each(table)(name, pan, timeout)
describe.each([
[1, 1, 2],
[1, 2, 3],
[2, 1, 3],
])(".add(%i, %i)", (a, b, expected) => {
test(`returns ${expected}`, () => {
expect(a + b).toBe(expected);
});
test(`returned value not be greater than ${expected}`, () => {
expect(a + b).not.toBeGreaterThan(expected);
});
test(`returned value not be less than ${expected}`, () => {
expect(a + b).not.toBeLessThan(expected);
});
});
Discussion