Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@skava/forms / src / validators / __tests__ / email.test.ts
Size: Mime:
/* eslint-disable max-statements */
import { isEmail } from '../'

// @todo - enable, finish, haven't run, meeting
describe('validators.email', () => {
  /**
   * @author https://en.wikipedia.org/wiki/Email_address#Valid_email_addresses
   */
  it('allows valid emails', () => {
    expect(isEmail('nicklas@ansman.se')).toBeTruthy()
    expect(isEmail('NiCkLaS@AnSmAn.Se')).toBeTruthy()

    expect(isEmail('niceandsimple@example.com')).toBeTruthy()
    expect(isEmail('very.common@example.com')).toBeTruthy()
    expect(isEmail('a.little.lengthy.but.fine@dept.example.com')).toBeTruthy()
    expect(isEmail('disposable.style.email.with+symbol@example.com')).toBeTruthy()
    expect(isEmail('other.email-with-dash@example.com')).toBeTruthy()
    expect(isEmail('üñîçøðé@example.com')).toBeTruthy()
    expect(isEmail('foo@some.customtld')).toBeTruthy()
  })

  it('does not allow undefined values', () => {
    expect(isEmail(undefined)).toBeFalsy()
    expect(isEmail(undefined)).toBeFalsy()
  })
  it('does not not allow non strings', () => {
    expect(isEmail(3.14)).toBeFalsy()
    expect(isEmail(true)).toBeFalsy()
  })

  /**
   * @author https://en.wikipedia.org/wiki/Email_address#Invalid_email_addresses
   */
  it('does not allow `invalid` emails', () => {
    const expected = false
    expect(isEmail('')).toEqual(expected)
    expect(isEmail(' ')).toEqual(expected)
    expect(isEmail('foobar')).toEqual(expected)
    expect(isEmail('foo@bar')).toEqual(expected)

    expect(isEmail('abc.example.com')).toEqual(expected)
    expect(isEmail('a@b@c@example.com')).toEqual(expected)
    expect(isEmail('a"b(c)d,e:f;g<h>i[j\\k]l@example.com')).toEqual(expected)
    expect(isEmail('just"not"right@example.com')).toEqual(expected)
    expect(isEmail('this is"not\\allowed@example.com')).toEqual(expected)
    expect(isEmail('this\\ still\\"not\\\\allowed@example.com')).toEqual(expected)
  })
})