diff --git a/components/tag/__tests__/index.test.tsx b/components/tag/__tests__/index.test.tsx index a46d9f8cd1..81ca509ade 100644 --- a/components/tag/__tests__/index.test.tsx +++ b/components/tag/__tests__/index.test.tsx @@ -1,6 +1,7 @@ import React from 'react'; import { Simulate } from 'react-dom/test-utils'; +import { CheckCircleOutlined } from '@ant-design/icons'; import Tag from '..'; import { resetWarned } from '../../_util/warning'; @@ -135,6 +136,11 @@ describe('Tag', () => { expect(onClick).not.toHaveBeenCalled(); }); + it('should only render icon when no children', () => { + const { container } = render(} />); + expect(container.querySelector('.ant-tag ')?.childElementCount).toBe(1); + }); + it('deprecated warning', () => { resetWarned(); const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); diff --git a/components/tag/index.tsx b/components/tag/index.tsx index 06a5ed1b63..d26f5d2aa1 100644 --- a/components/tag/index.tsx +++ b/components/tag/index.tsx @@ -128,7 +128,7 @@ const InternalTag: React.ForwardRefRenderFunction = ( const kids: React.ReactNode = iconNode ? ( <> {iconNode} - {children} + {children && {children}} ) : ( children