Add test case for Tooltip and Icon

This commit is contained in:
afc163 2018-09-03 17:41:48 +08:00
parent 3cbb5da6c2
commit 54a1534a3d

View File

@ -1,7 +1,8 @@
import React from 'react';
import { render } from 'enzyme';
import { render, mount } from 'enzyme';
import Icon from '..';
import ReactIcon from '@ant-design/icons-react';
import Tooltip from '../../tooltip';
import { getThemeFromTypeName, withThemeSuffix } from '../utils';
describe('Icon', () => {
@ -72,6 +73,29 @@ describe('Icon', () => {
expect(wrapper).toMatchSnapshot();
});
it('should support wrapped by Tooltip', () => {
const onVisibleChange = jest.fn();
const wrapper = mount(
<Tooltip
title="xxxxx"
mouseEnterDelay={0}
mouseLeaveDelay={0}
onVisibleChange={onVisibleChange}
>
<Icon type="home" />
</Tooltip>
);
expect(wrapper.find('i')).toHaveLength(1);
const icon = wrapper.find('i').at(0);
icon.simulate('mouseenter');
expect(onVisibleChange).toBeCalledWith(true);
expect(wrapper.instance().tooltip.props.visible).toBe(true);
icon.simulate('mouseleave');
expect(onVisibleChange).toBeCalledWith(false);
expect(wrapper.instance().tooltip.props.visible).toBe(false);
});
describe('`component` prop', () => {
it('can access to svg defs if has children', () => {
const wrapper = render(