Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion packages/zod-form-adapter/tests/FormApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,32 @@ describe('zod form api', () => {
form,
name: 'name',
validators: {
onChange: z.string().min(3, 'You must have a length of at least 3'),
onChange: z
.string()
.min(3, 'You must have a length of at least 3')
.regex(/^[a-z]+$/i, 'You must have only letters'),
},
})

field.mount()

// valid by default
expect(field.getMeta().errors).toEqual([])

// too short
field.setValue('a')
expect(field.getMeta().errors).toEqual([
'You must have a length of at least 3',
])

// too short and invalid character
field.setValue('a#')
expect(field.getMeta().errors).toEqual([
'You must have a length of at least 3',
'You must have only letters',
])

// valid
field.setValue('asdf')
expect(field.getMeta().errors).toEqual([])
})
Expand Down
Loading