Skip to content

Commit

Permalink
test(form-core): add onChange validation test (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
crutchcorn authored Aug 29, 2023
1 parent c392c61 commit 5f2935c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/form-core/src/tests/FieldApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,30 @@ describe('field api', () => {

expect(subfield.getValue()).toBe('one')
})

it('should run validation onChange', async () => {
const form = new FormApi({
defaultValues: {
name: 'test',
},
})

const field = new FieldApi({
form,
name: 'name',
onChange: (value) => {
if (value === 'other') {
return 'Please enter a different value'
}

return
},
})

field.mount()

expect(field.getMeta().error).toBeUndefined()
field.setValue('other', { touch: true })
expect(field.getMeta().error).toBe('Please enter a different value')
})
})

0 comments on commit 5f2935c

Please sign in to comment.