Last active
October 21, 2021 17:06
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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