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

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