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

75 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-01-31 01:21:21 +03:00
import test from 'ava'
import f from '../dist'
const rules = f.rules
const error = ({field, value, label}) => {
2018-01-31 01:21:21 +03:00
return `${field}${label}`
}
test('test required rule failure', async t => {
let v = await rules.required({field: 'name', value: '', error, label: 'xyz'})
2018-01-31 01:21:21 +03:00
t.is('string', typeof v)
t.is('namexyz', v)
})
2018-02-01 01:20:29 +03:00
test('test required rule empty array failure', async t => {
let v = await rules.required({field: 'name', value: [], error, label: 'xyz'})
2018-02-01 01:20:29 +03:00
t.is('namexyz', v)
})
2018-01-31 01:21:21 +03:00
test('test required rule passes', async t => {
t.is(false, await rules.required({field: 'name', value: 'Justin'}))
})
test('test email rule with valid email', async t => {
t.is(false, await rules.email({field: 'email', value: 'valid@example.com'}))
})
test('test email rule with invalid email', async t => {
t.is('email123', await rules.email({field: 'email', value: 'invalid@example', error, label: '123'}))
2018-01-31 01:21:21 +03:00
})
test('test email with empty email', async t => {
t.is(false, await rules.email({field: 'email', value: '', error}))
})
test('test confirmed passes', async t => {
t.is(false, await rules.confirmed({
field: 'password',
value: 'password',
label: '123',
2018-01-31 01:21:21 +03:00
error,
values: {password_confirmation: 'password'}
}))
2018-01-31 01:21:21 +03:00
})
test('test confirmed passes custom field', async t => {
t.is(false, await rules.confirmed({
field: 'password',
value: 'password',
label: '123',
2018-01-31 01:21:21 +03:00
error,
values: {customfield: 'password'}
}, 'customfield'))
2018-01-31 01:21:21 +03:00
})
test('test confirmed fails', async t => {
t.is('password123', await rules.confirmed({
field: 'password',
value: 'password',
label: '123',
2018-01-31 01:21:21 +03:00
error,
values: {password_confirmation: 'pAssword'}
}))
2018-01-31 01:21:21 +03:00
})
test('test empty confirmed passes', async t => {
t.is(false, await rules.confirmed({
field: 'password',
value: '',
label: '123',
2018-01-31 01:21:21 +03:00
error,
values: {password_confirmation: ''}
}))
2018-01-31 01:21:21 +03:00
})