diff --git a/packages/vee-validate/src/useForm.ts b/packages/vee-validate/src/useForm.ts index d377673ac..d1eec09d4 100644 --- a/packages/vee-validate/src/useForm.ts +++ b/packages/vee-validate/src/useForm.ts @@ -393,6 +393,8 @@ export function useForm = Record { expect.anything() ); }); + +// #3664 +test('clears old errors path when item is removed when no form schema is present', async () => { + const onSubmit = jest.fn(); + mountWithHoc({ + setup() { + const initialValues = { + users: [{ name: '' }, { name: '' }, { name: '' }], + }; + + const schema = yup.string().required(); + + return { + onSubmit, + schema, + initialValues, + }; + }, + template: ` + + +
+ User #{{ idx }} + + + + + +
+
+ + +
    +
  • {{ error }}
  • +
+ + +
+ `, + }); + + await flushPromises(); + const submitBtn = document.querySelector('.submit') as HTMLButtonElement; + const errorList = document.querySelector('ul') as HTMLUListElement; + const removeBtnAt = (idx: number) => document.querySelectorAll('.remove')[idx] as HTMLButtonElement; // remove the second item + + submitBtn.click(); + await flushPromises(); + expect(errorList.children).toHaveLength(3); + removeBtnAt(1).click(); + await flushPromises(); + + expect(errorList.children).toHaveLength(2); +});