mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 17:44:35 +08:00
fix: 修复 Tag onClick 为 undefined 的判断方式 (#40023)
* fix: 修复 Tag onClick 为 undefined 的判断方式 * feat: function
This commit is contained in:
parent
c74b93b2df
commit
81a1ffd53c
@ -8,6 +8,19 @@ import mountTest from '../../../tests/shared/mountTest';
|
||||
import rtlTest from '../../../tests/shared/rtlTest';
|
||||
import { act, render, fireEvent } from '../../../tests/utils';
|
||||
|
||||
(global as any).isVisible = true;
|
||||
|
||||
jest.mock('rc-util/lib/Dom/isVisible', () => {
|
||||
const mockFn = () => (global as any).isVisible;
|
||||
return mockFn;
|
||||
});
|
||||
|
||||
function waitRaf() {
|
||||
act(() => {
|
||||
jest.advanceTimersByTime(100);
|
||||
});
|
||||
}
|
||||
|
||||
describe('Tag', () => {
|
||||
mountTest(Tag);
|
||||
mountTest(Tag.CheckableTag);
|
||||
@ -152,4 +165,10 @@ describe('Tag', () => {
|
||||
expect(onChange).toHaveBeenCalledWith(true);
|
||||
});
|
||||
});
|
||||
it('should onClick is undefined', async () => {
|
||||
const { container } = render(<Tag onClick={undefined} />);
|
||||
fireEvent.click(container.querySelectorAll('.ant-tag')[0]);
|
||||
waitRaf();
|
||||
expect(document.querySelector('.ant-wave')).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
@ -119,7 +119,8 @@ const InternalTag: React.ForwardRefRenderFunction<HTMLSpanElement, TagProps> = (
|
||||
};
|
||||
|
||||
const isNeedWave =
|
||||
'onClick' in props || (children && (children as React.ReactElement<any>).type === 'a');
|
||||
typeof props.onClick === 'function' ||
|
||||
(children && (children as React.ReactElement<any>).type === 'a');
|
||||
const iconNode = icon || null;
|
||||
const kids = iconNode ? (
|
||||
<>
|
||||
|
Loading…
Reference in New Issue
Block a user