Skip to content

Commit

Permalink
tests: 更新 #4024模拟测试的代码
Browse files Browse the repository at this point in the history
  • Loading branch information
charlzyx authored Dec 28, 2023
1 parent 3db61ad commit 70c27dc
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions packages/core/src/__tests__/form.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ test('form lifecycle can be triggered after call form.setXXX', () => {
expect(valuesTriggerNum).toEqual(6)
})

test('reference initialValue should forceClear in destory', async () => {
test('reference initialValue should forceClear in destory, fix 4024', () => {
const form = attach(createForm())
const arr1 = attach(
form.createArrayField({
Expand All @@ -1165,7 +1165,7 @@ test('reference initialValue should forceClear in destory', async () => {
})
)

const arr2 = attach(
attach(
form.createArrayField({
name: 'bb',
basePath: 'aa.0',
Expand All @@ -1180,11 +1180,12 @@ test('reference initialValue should forceClear in destory', async () => {
initialValue: true,
})
)
// console.log('check init');

expect(form.initialValues).toEqual({
aa: [{ bb: [{ cc: true }] }],
})

// 模拟两次 antd/ArrayBase.Addation 点击
attach(
form.createField({
name: 'cc',
Expand All @@ -1199,16 +1200,28 @@ test('reference initialValue should forceClear in destory', async () => {
initialValue: true,
})
)
// await arr2.push({...arr2.props.initialValue?.[0]})
// await arr2.push({...arr2.props.initialValue?.[0]})

// 符合 formily DevTools 表现
expect(form.initialValues).toEqual({
aa: [{ bb: [{ cc: true }, { cc: true }, { cc: true }] }],
})
// 模拟 antd/ArrayBase.Remove 点击
arr1.remove(0)

arr1.unshift()
arr1.push(arr2.props.initialValue)

// 模拟一次外部数组点击 antd/ArrayBase.Addation 点击
attach(
form.createArrayField({
name: 'bb',
basePath: 'aa.0',
initialValue: [{}],
})
)
attach(
form.createField({
name: 'cc',
basePath: 'aa.0.bb.0',
initialValue: true,
})
)
expect(form.initialValues).toEqual({
aa: [{ bb: [{ cc: true }] }],
})
Expand Down

0 comments on commit 70c27dc

Please sign in to comment.