|
1 | | -import { FieldMeta, FormContext, FormMeta, useField, useForm, defineRule, configure } from '@/vee-validate'; |
| 1 | +import { |
| 2 | + FieldMeta, |
| 3 | + FormContext, |
| 4 | + FormMeta, |
| 5 | + useField, |
| 6 | + useForm, |
| 7 | + defineRule, |
| 8 | + configure, |
| 9 | + FieldContext, |
| 10 | +} from '@/vee-validate'; |
2 | 11 | import { mountWithHoc, setValue, flushPromises, dispatchEvent } from './helpers'; |
3 | 12 | import * as yup from 'yup'; |
4 | 13 | import { onMounted, ref, Ref } from 'vue'; |
5 | 14 | import { ModelComp, CustomModelComp } from './helpers/ModelComp'; |
6 | | -import { FieldContext } from '../dist/vee-validate'; |
7 | 15 |
|
8 | 16 | describe('useForm()', () => { |
9 | 17 | const REQUIRED_MESSAGE = 'Field is required'; |
@@ -1292,4 +1300,55 @@ describe('useForm()', () => { |
1292 | 1300 | expect(form.values.lname).toBeUndefined(); |
1293 | 1301 | expect(form.values.fname).toBe('test'); |
1294 | 1302 | }); |
| 1303 | + |
| 1304 | + test('reset should not make unspecified values undefined', async () => { |
| 1305 | + let form!: FormContext<{ fname: string; lname: string }>; |
| 1306 | + |
| 1307 | + mountWithHoc({ |
| 1308 | + setup() { |
| 1309 | + form = useForm({ |
| 1310 | + initialValues: { fname: '123', lname: '456' }, |
| 1311 | + }); |
| 1312 | + |
| 1313 | + form.defineField('fname'); |
| 1314 | + form.defineField('lname'); |
| 1315 | + |
| 1316 | + return {}; |
| 1317 | + }, |
| 1318 | + template: ` |
| 1319 | + <div></div> |
| 1320 | + `, |
| 1321 | + }); |
| 1322 | + |
| 1323 | + await flushPromises(); |
| 1324 | + |
| 1325 | + form.resetForm({ values: { fname: 'test' } }); |
| 1326 | + expect(form.values.lname).toBe('456'); |
| 1327 | + expect(form.values.fname).toBe('test'); |
| 1328 | + }); |
| 1329 | + |
| 1330 | + test('reset field should make the dirty state false', async () => { |
| 1331 | + let form!: FormContext<{ fname: string; lname: string }>; |
| 1332 | + |
| 1333 | + mountWithHoc({ |
| 1334 | + setup() { |
| 1335 | + form = useForm({ |
| 1336 | + initialValues: { fname: '123', lname: '456' }, |
| 1337 | + }); |
| 1338 | + |
| 1339 | + form.defineField('fname'); |
| 1340 | + form.defineField('lname'); |
| 1341 | + |
| 1342 | + return {}; |
| 1343 | + }, |
| 1344 | + template: ` |
| 1345 | + <div></div> |
| 1346 | + `, |
| 1347 | + }); |
| 1348 | + |
| 1349 | + await flushPromises(); |
| 1350 | + |
| 1351 | + form.resetField('fname', { value: 'test' }); |
| 1352 | + expect(form.meta.value.dirty).toBe(false); |
| 1353 | + }); |
1295 | 1354 | }); |
0 commit comments