Skip to content

Commit

Permalink
fix forcePopupAlign null
Browse files Browse the repository at this point in the history
  • Loading branch information
afc163 committed Nov 17, 2020
1 parent a92703d commit 69dc592
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/common/SliderTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const SliderTooltip = React.forwardRef<unknown, TooltipProps>((props, ref) => {

function keepAlign() {
rafRef.current = raf(() => {
innerRef.current.forcePopupAlign();
innerRef.current?.forcePopupAlign();
});
}

Expand Down
51 changes: 33 additions & 18 deletions tests/common/SliderTooltip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,37 @@ import { mount } from 'enzyme';
import { act } from 'react-dom/test-utils';
import SliderTooltip from '../../src/common/SliderTooltip';

it('should keepAlign by calling forcePopupAlign', async () => {
let ref;
mount(
<SliderTooltip
title="30"
visible
ref={node => {
ref = node;
}}
>
<span>aaaa</span>
</SliderTooltip>,
);
ref.forcePopupAlign = jest.fn();
await act(async () => {
await new Promise(res => setTimeout(res, 200));
describe('SliderTooltip', () => {
it('should keepAlign by calling forcePopupAlign', async () => {
let ref;
mount(
<SliderTooltip
title="30"
visible
ref={node => {
ref = node;
}}
>
<span>aaaa</span>
</SliderTooltip>,
);
ref.forcePopupAlign = jest.fn();
await act(async () => {
await new Promise(res => setTimeout(res, 200));
});
expect(ref.forcePopupAlign).toHaveBeenCalled();
});
expect(ref.forcePopupAlign).toHaveBeenCalled();
});

it('should not crash when unmount', async () => {
const wrapper = mount(
<SliderTooltip
title="30"
visible
>
<span>aaaa</span>
</SliderTooltip>,
);
wrapper.unmount();
});
})

0 comments on commit 69dc592

Please sign in to comment.