use built-in test.each instead of jest-in-case
p10ns11y opened this issue · 1 comments
p10ns11y commented
isn't the following is more readable and better than what we have in src/utils/__tests__/auth.final.extra-3.js
test.each([
['a2c!', 'too short', false],
['123456!', 'no alphabet characters', false],
['ABCdef!', 'no numbers', false],
['abc123!', 'no uppercase letters', false],
['ABC123!', 'no lowercase letters', false],
['ABCdef123', 'no non-alphanumeric characters', false]
])('password %s is invalid for being %s', (password, reason, isValid) => {
expect(isPasswordAllowed(password)).toBe(isValid)
})
// Or Template literal
test.each`
password | reason | isValid
${'a2c!'} | ${'too short'} | ${false}
${'123456!'} | ${'no alphabet characters'} | ${false}
${'ABCdef!'} | ${'no numbers'} | ${false}
${'abc123!'} | ${'no uppercase letters'} | ${false}
${'ABC123!'} | ${'no lowercase letters'} | ${false}
${'ABCdef123'}| ${'no non-alphanumeric characters'} | ${false}
`('password $password is invalid for being $reason', ({password, isValid}) => {
expect(isPasswordAllowed(password)).toBe(isValid)
})
kentcdodds commented
You can feel free to use test.each
. I personally don't feel like it's any more readable which is why I don't use test.each
:)