|
1 | | -import { defineRule, useField, Form, Field, useIsValidating } from '@/vee-validate'; |
| 1 | +import { defineRule, useField, Form, Field, useIsValidating, useForm } from '@/vee-validate'; |
2 | 2 | import { mountWithHoc, setValue, setChecked, dispatchEvent, flushPromises } from './helpers'; |
3 | 3 | import * as yup from 'yup'; |
4 | 4 | import { computed, defineComponent, onErrorCaptured, ref, Ref } from 'vue'; |
5 | | -import { InvalidSubmissionContext } from '../src/types'; |
| 5 | +import { InvalidSubmissionContext, PrivateFormContext } from '../src/types'; |
6 | 6 |
|
7 | 7 | describe('<Form />', () => { |
8 | 8 | const REQUIRED_MESSAGE = `This field is required`; |
@@ -3141,3 +3141,40 @@ test('radio fields with single field component binding', async () => { |
3141 | 3141 | expect(model.value).toBe('Tea'); |
3142 | 3142 | expect(submit).toHaveBeenLastCalledWith({ drink: 'Tea' }, expect.anything()); |
3143 | 3143 | }); |
| 3144 | + |
| 3145 | +// #4643 |
| 3146 | +test('removes proper pathState when field is unmounting', async () => { |
| 3147 | + const renderTemplateField = ref(false); |
| 3148 | + let form!: PrivateFormContext; |
| 3149 | + |
| 3150 | + mountWithHoc({ |
| 3151 | + template: ` |
| 3152 | + <form> |
| 3153 | + <Field v-if="renderTemplateField" name="foo" rules="required" /> |
| 3154 | + </form> |
| 3155 | + `, |
| 3156 | + setup() { |
| 3157 | + form = useForm() as unknown as PrivateFormContext; |
| 3158 | + useField('foo'); |
| 3159 | + return { renderTemplateField }; |
| 3160 | + }, |
| 3161 | + }); |
| 3162 | + |
| 3163 | + expect(form.meta.value.valid).toBe(true); |
| 3164 | + expect(form.getAllPathStates()).toMatchObject([{ id: 0, path: 'foo' }]); |
| 3165 | + |
| 3166 | + renderTemplateField.value = true; |
| 3167 | + await flushPromises(); |
| 3168 | + |
| 3169 | + expect(form.meta.value.valid).toBe(false); |
| 3170 | + expect(form.getAllPathStates()).toMatchObject([ |
| 3171 | + { id: 0, path: 'foo' }, |
| 3172 | + { id: 1, path: 'foo' }, |
| 3173 | + ]); |
| 3174 | + |
| 3175 | + renderTemplateField.value = false; |
| 3176 | + await flushPromises(); |
| 3177 | + |
| 3178 | + expect(form.meta.value.valid).toBe(true); |
| 3179 | + expect(form.getAllPathStates()).toMatchObject([{ id: 0, path: 'foo' }]); |
| 3180 | +}); |
0 commit comments