Skip to content

Commit

Permalink
Merge branch 'feat/standard-schema-implementation' of https://github.…
Browse files Browse the repository at this point in the history
…com/Balastrong/form into feat/standard-schema-implementation
  • Loading branch information
Balastrong committed Dec 10, 2024
2 parents b5ed17a + 738b880 commit 3ef2ab0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
48 changes: 24 additions & 24 deletions packages/form-core/tests/standardSchemaValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,56 +106,56 @@ describe('standard schema validator', () => {

it('should support standard schema sync validation with zod', async () => {
const form = new FormApi({
defaultValues: {
email: '',
},
validators: {
onChange: z.object({
email: z.string().email('email must be an email address'),
}),
},
validatorAdapter: standardSchemaValidator(),
defaultValues: {
email: '',
},
validators: {
onChange: z.object({
email: z.string().email('email must be an email address'),
}),
},
validatorAdapter: standardSchemaValidator(),
})

const field = new FieldApi({
form,
name: 'email',
form,
name: 'email',
})

field.mount()

field.setValue('test')
expect(form.state.errors).toStrictEqual([
'email must be an email address',
'email must be an email address',
])
})

it('should support standard schema async validation with zod', async () => {
vi.useFakeTimers()

const form = new FormApi({
defaultValues: {
email: '',
},
validators: {
onChangeAsync: z.object({
email: z.string().email('email must be an email address'),
}),
},
validatorAdapter: standardSchemaValidator(),
defaultValues: {
email: '',
},
validators: {
onChangeAsync: z.object({
email: z.string().email('email must be an email address'),
}),
},
validatorAdapter: standardSchemaValidator(),
})

const field = new FieldApi({
form,
name: 'email',
form,
name: 'email',
})

field.mount()

field.setValue('test')
await vi.runAllTimersAsync()
expect(form.state.errors).toStrictEqual([
'email must be an email address',
'email must be an email address',
])
})

Expand Down
4 changes: 2 additions & 2 deletions packages/zod-form-adapter/tests/FormApi.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ it('should allow a Zod validator to handle the correct Zod type on async methods
it('should allow functional validators to be passed when using a validator adapter', () => {
const form = new FormApi({
defaultValues: {
name: 'test'
name: 'test',
},
validatorAdapter: zodValidator(),
validators: {
onChange: z.object({
name: z.string()
name: z.string(),
}),
onChangeAsync: () => null,
onBlur: () => null,
Expand Down

0 comments on commit 3ef2ab0

Please sign in to comment.