Skip to content

Commit 57a855b

Browse files
test(form-core): cover onMount field errors before field mount (#2223)
Co-authored-by: cyphercodes <cyphercodes@users.noreply.github.com> Co-authored-by: LeCarbonator <18158911+LeCarbonator@users.noreply.github.com>
1 parent 7b8fc1d commit 57a855b

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

packages/form-core/tests/FormApi.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3203,6 +3203,36 @@ describe('form api', () => {
32033203
)
32043204
})
32053205

3206+
it("preserves field errors from the form's onMount validator before fields mount", () => {
3207+
const form = new FormApi({
3208+
defaultValues: {
3209+
firstName: '',
3210+
},
3211+
validators: {
3212+
onMount: () => ({
3213+
fields: {
3214+
firstName: 'first name is required',
3215+
},
3216+
}),
3217+
},
3218+
})
3219+
3220+
form.mount()
3221+
3222+
const firstNameField = new FieldApi({
3223+
form,
3224+
name: 'firstName',
3225+
})
3226+
3227+
firstNameField.mount()
3228+
3229+
expect(firstNameField.state.meta.errorMap.onMount).toBe(
3230+
'first name is required',
3231+
)
3232+
expect(firstNameField.state.meta.errorSourceMap.onMount).toBe('form')
3233+
expect(firstNameField.state.meta.errors).toEqual(['first name is required'])
3234+
})
3235+
32063236
it('clears errors on all fields affected by form validation when condition resolves', () => {
32073237
const form = new FormApi({
32083238
defaultValues: {

0 commit comments

Comments
 (0)