From d58c0780f9a8a2bc398b96a33b351a4ada6a7e61 Mon Sep 17 00:00:00 2001 From: afc163 Date: Fri, 25 May 2018 20:34:53 +0800 Subject: [PATCH] test Popconfirm --- components/popconfirm/__tests__/index.test.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/components/popconfirm/__tests__/index.test.js b/components/popconfirm/__tests__/index.test.js index e699e54802..4bc14127f4 100644 --- a/components/popconfirm/__tests__/index.test.js +++ b/components/popconfirm/__tests__/index.test.js @@ -45,4 +45,41 @@ describe('Popconfirm', () => { expect(popup.innerHTML).toMatchSnapshot(); expect(popup.innerHTML).toMatchSnapshot(); }); + + it('should be controlled by visible', () => { + jest.useFakeTimers(); + const popconfirm = mount( + + show me your code + + ); + expect(popconfirm.instance().getPopupDomNode()).toBeFalsy(); + popconfirm.setProps({ visible: true }); + expect(popconfirm.instance().getPopupDomNode()).toBeTruthy(); + expect(popconfirm.instance().getPopupDomNode().className).not.toContain('ant-popover-hidden'); + popconfirm.setProps({ visible: false }); + jest.runAllTimers(); + expect(popconfirm.instance().getPopupDomNode().className).toContain('ant-popover-hidden'); + jest.useRealTimers(); + }); + + it('should trigger onConfirm and onCancel', () => { + const confirm = jest.fn(); + const cancel = jest.fn(); + const onVisibleChange = jest.fn(); + const popconfirm = mount( + + show me your code + + ); + const triggerNode = popconfirm.find('span').at(0); + triggerNode.simulate('click'); + popconfirm.find('.ant-btn-primary').simulate('click'); + expect(confirm).toHaveBeenCalled(); + expect(onVisibleChange).toHaveBeenLastCalledWith(false); + triggerNode.simulate('click'); + popconfirm.find('.ant-btn').at(0).simulate('click'); + expect(cancel).toHaveBeenCalled(); + expect(onVisibleChange).toHaveBeenLastCalledWith(false); + }); });