email.test.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { expect } from 'chai'
  2. import { isValidEmail } from '../../../../frontend/js/shared/utils/email'
  3. const validEmailAddresses = [
  4. 'email@example.com',
  5. 'firstname.lastname@example.com',
  6. 'firstname-lastname@example.com',
  7. 'email@subdomain.example.com',
  8. 'firstname+lastname@example.com',
  9. '1234567890@example.com',
  10. 'email@example-one.com',
  11. '_@example.com',
  12. 'email@example.name',
  13. 'email@example.co.jp',
  14. ]
  15. const invalidEmailAddresses = [
  16. 'plaintext',
  17. '#@%^%#$@#$@#.com',
  18. '@example.com',
  19. 'email.example.com',
  20. '.email@example.com',
  21. 'email.@example.com',
  22. 'email..email@example.com',
  23. 'email@example.com (Joe Smith)',
  24. 'email@example',
  25. 'email@111.222.333.44444',
  26. 'email@example..com',
  27. ]
  28. describe('isValidEmail', function () {
  29. it('should return true for valid email addresses', function () {
  30. validEmailAddresses.forEach(email =>
  31. expect(isValidEmail(email)).to.equal(true, email + ' should be valid ')
  32. )
  33. })
  34. it('should return false for invalid email addresses', function () {
  35. invalidEmailAddresses.forEach(email =>
  36. expect(isValidEmail(email)).to.equal(
  37. false,
  38. email + ' should not be valid '
  39. )
  40. )
  41. })
  42. })