From c270ad91128f3240934c6a495e42d1b0112be8b8 Mon Sep 17 00:00:00 2001 From: lijianan <574980606@qq.com> Date: Sat, 12 Sep 2026 14:01:08 +0800 Subject: [PATCH] update --- tests/field.test.tsx | 45 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/field.test.tsx b/tests/field.test.tsx index 20b6b2c4..f296bf15 100644 --- a/tests/field.test.tsx +++ b/tests/field.test.tsx @@ -2,6 +2,7 @@ import React from 'react'; import Form, { Field } from '../src'; import type { FormInstance } from '../src'; import { act, fireEvent, render } from '@testing-library/react'; +import { Input } from './common/InfoField'; import timeout from './common/timeout'; describe('Form.Field', () => { @@ -39,6 +40,50 @@ describe('Form.Field', () => { expect(formRef.getFieldsValue()).toEqual({ light: 'bamboo' }); }); + it('render props should receive initialValue on first render', () => { + let firstValue: any; + + render( +
+ + {control => { + if (firstValue === undefined) { + firstValue = control.value; + } + + return ; + }} + +
, + ); + + expect(firstValue).toBe('bamboo'); + }); + + it('unmount should use latest onMetaChange', () => { + const onMetaChange1 = jest.fn(); + const onMetaChange2 = jest.fn(); + + const Demo: React.FC<{ onMetaChange: (meta: any) => void }> = props => { + const { onMetaChange } = props; + return ( +
+ + + +
+ ); + }; + + const { rerender, unmount } = render(); + + rerender(); + unmount(); + + expect(onMetaChange1).not.toHaveBeenCalledWith(expect.objectContaining({ destroy: true })); + expect(onMetaChange2).toHaveBeenCalledWith(expect.objectContaining({ destroy: true })); + }); + // https://github.com/ant-design/ant-design/issues/51611 it('date type as change', async () => { const onValuesChange = jest.fn();