import React from 'react'; import { render, fireEvent } from '../../../tests/utils'; import Form from '..'; import Input from '../../input'; import Button from '../../button'; import type { InputRef } from '../../input'; interface TestProps { show?: boolean; onRef: (node: React.ReactNode, originRef: InputRef) => void; } describe('Form.Ref', () => { const Test: React.FC = ({ show, onRef }) => { const [form] = Form.useForm(); const removeRef = React.useRef(null); const testRef = React.useRef(null); const listRef = React.useRef(null); return (
{show && ( )} {(fields) => fields.map((field) => ( )) }
); }; it('should ref work', () => { const onRef = jest.fn(); const { container, rerender } = render(); fireEvent.click(container.querySelector('.ref-item')!); expect(onRef).toHaveBeenCalled(); expect(onRef.mock.calls[0][0]).toBe(onRef.mock.calls[0][1]); onRef.mockReset(); fireEvent.click(container.querySelector('.ref-list')!); expect(onRef).toHaveBeenCalled(); expect(onRef.mock.calls[0][0]).toBe(onRef.mock.calls[0][1]); onRef.mockReset(); rerender(); fireEvent.click(container.querySelector('.ref-remove')!); expect(onRef).toHaveBeenCalledWith(undefined, null); }); });