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

100% Statements 32/32
100% Branches 4/4
100% Functions 7/7
100% Lines 29/29
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 27 28 29 30 31 32 33 34 35 36 37 38     17×                
import assert from 'assert'
import { acceptance } from '../index'
import getErrorId from './helper'
 
const ERROR_ID = 'form.errors.acceptance'
 
function test (value, params) {
  return getErrorId(acceptance(params)(value))
}
 
describe('Validator: acceptance', function() {
  it('should be invalid when `value` is not included in default values', function() {
    assert.equal(ERROR_ID, test())
    assert.equal(ERROR_ID, test(false))
    assert.equal(ERROR_ID, test(''))
    assert.equal(ERROR_ID, test('foo'))
    assert.equal(ERROR_ID, test('false'))
  })
  it('should be valid when `value` is included in default values', function() {
    assert.ok(!test(1))
    assert.ok(!test('1'))
    assert.ok(!test('true'))
    assert.ok(!test(true))
  })
  it('should be valid when `value` is included in custom values', function() {
    assert.ok(!test(1,     { accept: '1' }))
    assert.ok(!test('1',   { accept: 1 }))
    assert.ok(!test('foo', { accept: 'foo' }))
    assert.ok(!test(2,     { accept: ['2'] }))
    assert.ok(!test('2',   { accept: ['foo', 2] }))
  })
  it('should be invalid when `value` is not included in custom values', function() {
    assert.equal(ERROR_ID, test(null, { accept: '1' }))
    assert.equal(ERROR_ID, test('2',  { accept: '1' }))
    assert.equal(ERROR_ID, test('2',  { accept: ['foo', 3] }))
  })
})