-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-suite.ts
37 lines (31 loc) · 1.04 KB
/
test-suite.ts
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
import { create, enforce, only, test } from 'vest'
export type FormData = {
email: string
firstName: string
lastName: string
}
export const initialData: FormData = { email: '', firstName: '', lastName: '' }
// Very default Vest suite. If that looks foreign to you, then look
// up the vest docs.
export const suite = create((data: FormData, currentField) => {
// If field name is supplied validate only that field
only(currentField)
test('email', 'Email is required', () => {
enforce(data.email).isNotBlank()
})
test('email', 'Email must contain @ sign', () => {
enforce(data.email).matches(/@/)
})
test('firstName', 'First name is required', () => {
enforce(data.firstName).isNotBlank()
})
test('firstName', 'First name must be at least 3 characters', () => {
enforce(data.firstName).longerThan(2)
})
test('lastName', 'Last name is required', () => {
enforce(data.lastName).isNotBlank()
})
test('lastName', 'Last name must be at least 3 characters', () => {
enforce(data.lastName).longerThan(2)
})
})