Skip to content

Commit

Permalink
test: verify zod validator returns ValidationError[]
Browse files Browse the repository at this point in the history
refs TanStack#942

Signed-off-by: Pascal Küsgen <[email protected]>
  • Loading branch information
Pascalmh committed Sep 9, 2024
1 parent 64fefaa commit ff9f67e
Showing 1 changed file with 16 additions and 1 deletion.
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

0 comments on commit ff9f67e

Please sign in to comment.