Skip to content

Commit efed0fa

Browse files
committed
test: add failing test
1 parent 1db827e commit efed0fa

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/useAjvForm.test.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,34 @@ describe('useAJVForm should properly set errors programmatically using setErrors
586586
expect(result.current.state.description.error).toBe('Monkey message');
587587
});
588588

589+
it('sets the errors using form.setErrors without affecting other state', () => {
590+
const initialData = { title: 'Foo', description: 'Bar' };
591+
const schema: JSONSchemaType<{ title: string; description: string }> = {
592+
type: 'object',
593+
required: ['title', 'description'],
594+
properties: {
595+
title: { type: 'string' },
596+
description: { type: 'string' },
597+
},
598+
};
599+
600+
const { result } = renderHook(() => useAJVForm(initialData, schema));
601+
602+
result.current.setErrors([
603+
{
604+
instancePath: '/description',
605+
keyword: 'required',
606+
params: { missingProperty: 'description' },
607+
schemaPath: '#/required',
608+
},
609+
]);
610+
611+
expect(result.current.state.title.value).toBe('Foo');
612+
expect(result.current.state.description.value).toBe('Bar');
613+
614+
expect(result.current.state.description.error).toBe('Monkey message');
615+
});
616+
589617
it('should handle conditional validations on locationType correctly', () => {
590618
/**
591619
* Test Scenario:

0 commit comments

Comments
 (0)