kentcdodds/testing-node-apps

use built-in test.each instead of jest-in-case

p10ns11y opened this issue · 1 comments

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)
})

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 :)