diff --git a/components/avatar/__tests__/Avatar.test.js b/components/avatar/__tests__/Avatar.test.js index 906ed81917..6380a7bd90 100644 --- a/components/avatar/__tests__/Avatar.test.js +++ b/components/avatar/__tests__/Avatar.test.js @@ -133,4 +133,15 @@ describe('Avatar Render', () => { wrapper.setProps({ children: 'xx' }); expect(wrapper.state().scale).toBe(0.32); }); + + it('should warning when pass a string as icon props', () => { + const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + mount(); + expect(warnSpy).not.toHaveBeenCalled(); + mount(); + expect(warnSpy).toHaveBeenCalledWith( + `Warning: [antd: Avatar] \`icon\` is using ReactNode instead of string naming in v4. Please check \`user\` at https://ant.design/components/icon`, + ); + warnSpy.mockRestore(); + }); }); diff --git a/components/avatar/index.tsx b/components/avatar/index.tsx index 3c395ed9f5..a911413b25 100644 --- a/components/avatar/index.tsx +++ b/components/avatar/index.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import classNames from 'classnames'; import { ConfigConsumer, ConfigConsumerProps } from '../config-provider'; +import warning from '../_util/warning'; export interface AvatarProps { /** Shape of avatar, options:`circle`, `square` */ @@ -108,6 +109,12 @@ export default class Avatar extends React.Component { ...others } = this.props; + warning( + !(typeof icon === 'string' && icon.length > 2), + 'Avatar', + `\`icon\` is using ReactNode instead of string naming in v4. Please check \`${icon}\` at https://ant.design/components/icon`, + ); + const { isImgExist, scale, mounted } = this.state; const prefixCls = getPrefixCls('avatar', customizePrefixCls); diff --git a/components/button/__tests__/index.test.js b/components/button/__tests__/index.test.js index 9baf70cde9..0d9dc2840d 100644 --- a/components/button/__tests__/index.test.js +++ b/components/button/__tests__/index.test.js @@ -233,4 +233,15 @@ describe('Button', () => { wrapper.unmount(); }).not.toThrow(); }); + + it('should warning when pass a string as icon props', () => { + const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {}); + mount(