Skip to content

Instantly share code, notes, and snippets.

@phatnguyenuit
Last active October 21, 2021 17:06
Show Gist options
  • Save phatnguyenuit/851c2742294dee460fb38056caa0da23 to your computer and use it in GitHub Desktop.
Save phatnguyenuit/851c2742294dee460fb38056caa0da23 to your computer and use it in GitHub Desktop.
Prevent code duplication when writing unit tests with Jest .each - it.each test cases
import { toKebabCase } from './utils';
describe('toKebabCase', () => {
it.each`
text | expectedResult
${''} | ${''}
${'my_example'} | ${'my-example'}
${'Another-Example'} | ${'another-example'}
${'anotherExample'} | ${'another-example'}
${'anotherExample123'} | ${'another-example-1-2-3'}
`(
'should return "$expectedResult" when given "$text"',
({ text, expectedResult }) => {
expect(toKebabCase(text)).toEqual(expectedResult);
},
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment