Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jest-in-case #16

Open
xerosanyam opened this issue Dec 27, 2021 · 1 comment
Open

jest-in-case #16

xerosanyam opened this issue Dec 27, 2021 · 1 comment

Comments

@xerosanyam
Copy link

xerosanyam commented Dec 27, 2021

starting jest27, instead of jest-in-case, test.each can be used because it doesn't require any extra library

@ACPK
Copy link

ACPK commented Jul 10, 2023

Here's an example of repetitive Jest test cases with test.each.

import {isPasswordAllowed} from '../auth'

describe('isPasswordAllowed', () => {
  const validPasswords = [['valid password', '!aBc1234']]

  const invalidPasswords = [
    ['too short', 'a2c!'],
    ['no letters', '123456!'],
    ['no numbers', 'ABCdef!'],
    ['no uppercase letters', 'abc123!'],
    ['no lowercase letters', 'ABC123!'],
    ['no non-alphanumeric characters', 'ABCdef123'],
  ]

  test.each(validPasswords)('%p - %p', (firstArgs, secondArgs) => {
    expect(isPasswordAllowed(secondArgs)).toBe(true)
  })

  test.each(invalidPasswords)('%p - %p', (firstArgs, secondArgs) => {
    expect(isPasswordAllowed(secondArgs)).toBe(false)
  })
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants