test Popconfirm

This commit is contained in:
afc163 2018-05-25 20:34:53 +08:00 committed by 偏右
parent aff9d8fc62
commit d58c0780f9

View File

@ -45,4 +45,41 @@ describe('Popconfirm', () => {
expect(popup.innerHTML).toMatchSnapshot(); expect(popup.innerHTML).toMatchSnapshot();
expect(popup.innerHTML).toMatchSnapshot(); expect(popup.innerHTML).toMatchSnapshot();
}); });
it('should be controlled by visible', () => {
jest.useFakeTimers();
const popconfirm = mount(
<Popconfirm title="code">
<span>show me your code</span>
</Popconfirm>
);
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(
<Popconfirm title="code" onConfirm={confirm} onCancel={cancel} onVisibleChange={onVisibleChange}>
<span>show me your code</span>
</Popconfirm>
);
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);
});
}); });