Today I Learned

A Hashrocket project

Table tests with Jest

Jest has a nice helper function that allow us to run table tests. Check this out:

const cases = [
  ["user@email.com", true],
  ["user-1@email.com", true],
  ["@email.com", false],
  ["user@", false],
  ["useremail.com", false],
]

test.each()("validateEmail(%s) should be %s", (email, expected) => {
  expect(validateEmail(email)).toEqual(expected);
});

Here’s the documentation

Looking for help? At Hashrocket, our JavaScript experts launch scalable, performant apps on the Web, Android and iOS. Contact us and find out how we can help you.