1
0
mirror of synced 2024-11-23 05:46:05 +03:00
vue-formulario/tests/formulate.test.js

44 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-01-31 01:21:21 +03:00
import test from 'ava'
import formulate from '../dist'
import VueMock from './mocks/VueMock'
test('checks plugin registration', async t => {
let components = []
VueMock.component = (name, object) => components.push({name, object})
formulate.install(VueMock)
t.truthy(VueMock.prototype.$formulate)
t.is(2, components.length)
})
test('parses single rule', async t => {
let rules = formulate.parseRules('required')
t.deepEqual([{rule: 'required', args: []}], rules)
})
test('parses multiple rules and trims', async t => {
let rules = formulate.parseRules('email |required')
t.deepEqual([{rule: 'email', args: []}, {rule: 'required', args: []}], rules)
})
test('parses rule arguments', async t => {
let rules = formulate.parseRules('required(Name)|equals(confirm_password, Your Password)')
t.deepEqual([
{rule: 'required', args: ['Name']},
{rule: 'equals', args: ['confirm_password', 'Your Password']}
], rules)
})
test('tests single validation error', async t => {
t.is(1, (await formulate.validationErrors({field: 'email', value: ''}, 'required')).length)
})
test('tests multiple validation errors', async t => {
t.is(2, (await formulate.validationErrors({field: 'email', value: 'pastaparty'}, 'email|confirmed', {
email_confirmation: 'pizzaparty'
})).length)
})
test('tests empty validation string', async t => {
t.is(false, await formulate.validationErrors({field: 'email', value: 'pastaparty'}, false))
})