/* eslint-disable react/jsx-key */ import { mount } from 'enzyme'; import React from 'react'; import Form from '..'; import Button from '../../button'; import Input from '../../input'; describe('Form.Ref', () => { const Test = ({ onRef, show, }: { onRef: (node: React.ReactElement, originRef: React.RefObject) => void; show?: boolean; }) => { const [form] = Form.useForm(); const removeRef = React.useRef(); const testRef = React.useRef(); const listRef = React.useRef(); return (
{show && ( )} {fields => fields.map(field => ( )) }
); }; it('should ref work', () => { const onRef = jest.fn(); const wrapper = mount(); wrapper.find('.ref-item').last().simulate('click'); expect(onRef).toHaveBeenCalled(); expect(onRef.mock.calls[0][0]).toBe(onRef.mock.calls[0][1]); onRef.mockReset(); wrapper.find('.ref-list').last().simulate('click'); expect(onRef).toHaveBeenCalled(); expect(onRef.mock.calls[0][0]).toBe(onRef.mock.calls[0][1]); onRef.mockReset(); wrapper.setProps({ show: false }); wrapper.update(); wrapper.find('.ref-remove').last().simulate('click'); expect(onRef).toHaveBeenCalledWith(undefined, null); }); });