Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
describe.each でデータ行ごとに回す処理をテンプレートリテラルで書く方法
// https://jestjs.io/docs/en/api#describeeachtablename-fn-timeout
describe.each`
a | b | expected
${1} | ${1} | ${2}
${1} | ${2} | ${3}
${2} | ${1} | ${3}
`('$a + $b', ({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);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment