Browse Source

fix test case which fails a lot

pull/23240/head
afc163 5 years ago
parent
commit
59c0cdf3a2
  1. 49
      components/tooltip/__tests__/tooltip.test.js

49
components/tooltip/__tests__/tooltip.test.js

@ -128,18 +128,8 @@ describe('Tooltip', () => {
</Button> </Button>
</Tooltip>, </Tooltip>,
); );
expect( expect(wrapper1.find('span').first().getDOMNode().style.display).toBe('inline-block');
wrapper1 expect(wrapper2.find('span').first().getDOMNode().style.display).toBe('block');
.find('span')
.first()
.getDOMNode().style.display,
).toBe('inline-block');
expect(
wrapper2
.find('span')
.first()
.getDOMNode().style.display,
).toBe('block');
}); });
it('should works for arrowPointAtCenter', () => { it('should works for arrowPointAtCenter', () => {
@ -161,10 +151,7 @@ describe('Tooltip', () => {
</button> </button>
</Tooltip>, </Tooltip>,
); );
wrapper wrapper.find('button').at(0).simulate('click');
.find('button')
.at(0)
.simulate('click');
const popupLeftDefault = parseInt(wrapper.instance().getPopupDomNode().style.left, 10); const popupLeftDefault = parseInt(wrapper.instance().getPopupDomNode().style.left, 10);
const wrapper2 = mount( const wrapper2 = mount(
@ -181,10 +168,7 @@ describe('Tooltip', () => {
</button> </button>
</Tooltip>, </Tooltip>,
); );
wrapper2 wrapper2.find('button').at(0).simulate('click');
.find('button')
.at(0)
.simulate('click');
const popupLeftArrowPointAtCenter = parseInt( const popupLeftArrowPointAtCenter = parseInt(
wrapper2.instance().getPopupDomNode().style.left, wrapper2.instance().getPopupDomNode().style.left,
10, 10,
@ -272,22 +256,26 @@ describe('Tooltip', () => {
}).not.toThrow(); }).not.toThrow();
}); });
it('support other placement', async () => { it('support other placement', done => {
const wrapper = mount( const wrapper = mount(
<Tooltip <Tooltip
title="xxxxx" title="xxxxx"
placement="bottomLeft" placement="bottomLeft"
visible
transitionName="" transitionName=""
mouseEnterDelay={0} mouseEnterDelay={0}
afterVisibleChange={visible => {
if (visible) {
expect(wrapper.find('Trigger').props().popupPlacement).toBe('bottomLeft');
}
done();
}}
> >
<span> <span>Hello world!</span>
Hello world!
</span>
</Tooltip>, </Tooltip>,
); );
await sleep(1000); expect(wrapper.find('span')).toHaveLength(1);
expect(wrapper.instance().getPopupDomNode().className).toContain('placement-bottomLeft'); const button = wrapper.find('span').at(0);
button.simulate('mouseenter');
}); });
it('other placement when mouse enter', async () => { it('other placement when mouse enter', async () => {
@ -296,18 +284,17 @@ describe('Tooltip', () => {
title="xxxxx" title="xxxxx"
placement="topRight" placement="topRight"
transitionName="" transitionName=""
popupTransitionName=""
mouseEnterDelay={0} mouseEnterDelay={0}
> >
<span> <span>Hello world!</span>
Hello world!
</span>
</Tooltip>, </Tooltip>,
); );
expect(wrapper.find('span')).toHaveLength(1); expect(wrapper.find('span')).toHaveLength(1);
const button = wrapper.find('span').at(0); const button = wrapper.find('span').at(0);
button.simulate('mouseenter'); button.simulate('mouseenter');
await sleep(300); await sleep(500);
expect(wrapper.instance().getPopupDomNode().className).toContain('placement-topRight'); expect(wrapper.instance().getPopupDomNode().className).toContain('placement-topRight');
}); });
}); });

Loading…
Cancel
Save