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

100% Statements 20/20
100% Branches 4/4
100% Functions 5/5
100% Lines 17/17
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24                
import assert from 'assert'
import { absence } from '../index'
import getErrorId from './helper'
 
const ERROR_ID = 'form.errors.absence'
 
function test (value) {
  return getErrorId(absence()(value))
}
 
describe('Validator: absence', function () {
  it('should be invalid when `value` is not empty', function() {
    assert.equal(ERROR_ID, test(1))
    assert.equal(ERROR_ID, test('str'))
    assert.equal(ERROR_ID, test(' abc '))
  })
  it('should be valid when `value` is empty', function() {
    assert.ok(!test())
    assert.ok(!test(''))
    assert.ok(!test('   '))
    assert.ok(!test(' \n \t '))
  })
})