testing-node-apps
testing-node-apps copied to clipboard
jest-in-case
starting jest27, instead of jest-in-case
, test.each
can be used because it doesn't require any extra library
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)
})
})