From c2741c2c4b536152546c14dde38b324fb8f70d49 Mon Sep 17 00:00:00 2001 From: PCCCCCCC Date: Tue, 3 May 2022 10:40:12 +0800 Subject: [PATCH] test: transfer part of tooltip test case to testing library (#35362) --- components/tooltip/__tests__/tooltip.test.js | 41 +++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/components/tooltip/__tests__/tooltip.test.js b/components/tooltip/__tests__/tooltip.test.js index 1b90f29fd0..7a567a31ec 100644 --- a/components/tooltip/__tests__/tooltip.test.js +++ b/components/tooltip/__tests__/tooltip.test.js @@ -26,7 +26,7 @@ describe('Tooltip', () => { const onVisibleChange = jest.fn(); const ref = React.createRef(); - const wrapper = mount( + const { container, rerender } = render( { ); // `title` is empty. - const div = wrapper.find('#hello').at(0); - div.simulate('mouseenter'); + const divElement = container.querySelector('#hello'); + fireEvent.mouseEnter(divElement); expect(onVisibleChange).not.toHaveBeenCalled(); expect(ref.current.props.visible).toBe(false); - div.simulate('mouseleave'); + fireEvent.mouseLeave(divElement); expect(onVisibleChange).not.toHaveBeenCalled(); expect(ref.current.props.visible).toBe(false); // update `title` value. - wrapper.setProps({ title: 'Have a nice day!' }); - wrapper.find('#hello').simulate('mouseenter'); + rerender( + +
Hello world!
+
, + ); + fireEvent.mouseEnter(divElement); expect(onVisibleChange).toHaveBeenLastCalledWith(true); expect(ref.current.props.visible).toBe(true); - wrapper.find('#hello').simulate('mouseleave'); + fireEvent.mouseLeave(divElement); expect(onVisibleChange).toHaveBeenLastCalledWith(false); expect(ref.current.props.visible).toBe(false); // add `visible` props. - wrapper.setProps({ visible: false }); - wrapper.find('#hello').simulate('mouseenter'); + rerender( + +
Hello world!
+
, + ); + fireEvent.mouseEnter(divElement); expect(onVisibleChange).toHaveBeenLastCalledWith(true); const lastCount = onVisibleChange.mock.calls.length; expect(ref.current.props.visible).toBe(false); // always trigger onVisibleChange - wrapper.simulate('mouseleave'); + fireEvent.mouseLeave(divElement); expect(onVisibleChange.mock.calls.length).toBe(lastCount); // no change with lastCount expect(ref.current.props.visible).toBe(false); });