all files / src/__tests__/ email.spec.js

100% Statements 19/19
100% Branches 4/4
100% Functions 5/5
100% Lines 16/16
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23                
import assert from 'assert'
import { email } from '../index'
import getErrorId from './helper'
 
const ERROR_ID = 'form.errors.email'
 
function test (value, params) {
  return getErrorId(email(params)(value))
}
 
describe('Validator: email', function() {
  it('should be invalid when `value` is not a valid email', function() {
    assert.equal(ERROR_ID, test(''))
    assert.equal(ERROR_ID, test('foo'))
    assert.equal(ERROR_ID, test('foo@bar'))
    assert.equal(ERROR_ID, test('f@b.'))
  })
  it('should be valid when `value` is a valid email', function() {
    assert.ok(!test('a@b.com'))
    assert.ok(!test('foo@bar.net'))
  })
})