Repository URL to install this package:
|
Version:
3.1.2 ▾
|
/* 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)
})
})