From f736e62b1bb82f940d14d74a6d505c913c1c3dde Mon Sep 17 00:00:00 2001 From: Abdelrahman Awad Date: Sun, 23 Jan 2022 17:20:09 +0200 Subject: [PATCH] fix: clear old error path error when changing field name closes #3664 --- packages/vee-validate/src/useForm.ts | 2 + .../vee-validate/tests/FieldArray.spec.ts | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+) 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); +});