Skip to content

Commit

Permalink
test(*): fix icon test case
Browse files Browse the repository at this point in the history
  • Loading branch information
lakerswgq authored and 潕量 committed Jun 10, 2022
1 parent eb58732 commit c70ae13
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/icon/icon-font.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Icon from './icon';

const customCache = new Set();

const ConfigIcon = ConfigProvider.config(Icon);

/** Icon.createFromIconfontCN
* @description 通过自定义 iconfont源来使用使用svg格式的图片
* @order 1
Expand Down Expand Up @@ -58,11 +60,14 @@ export default function createFromIconfontCN(options = {}) {
);

return (
<Icon size={size}>
// FIXME: 这里理论上优先级是 props 中的 prefix 优先级更高,不过之前的行为一直是取上层 ConfigProvider 中的 prefix,
// 先兼容之前的表现,will be fixed in 2.x
// https://github.com/alibaba-fusion/next/issues/3906
<ConfigIcon size={size}>
<svg className={classes} focusable={false} {...others} {...extraCommonProps}>
{content}
</svg>
</Icon>
</ConfigIcon>
);
};

Expand Down
14 changes: 14 additions & 0 deletions test/icon/index-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Adapter from 'enzyme-adapter-react-16';
import assert from 'power-assert';
import Icon from '../../src/icon';

import ConfigProvider from '../../src/config-provider';

Enzyme.configure({ adapter: new Adapter() });

describe('Icon', () => {
Expand Down Expand Up @@ -48,4 +50,16 @@ describe('Icon', () => {
newWrapper.setProps({ size: 'xl' });
assert(newWrapper.find('.next-icon').hasClass('next-xl'));
});

it('createFromIconfontCN should support prefix', () => {
const CustomIcon = Icon.createFromIconfontCN({
scriptUrl: '//at.alicdn.com/t/font_1464085_egnk4s8yv2f.js',
});

const newWrapper = mount( <ConfigProvider prefix="abcd-">
<CustomIcon type="icon-pic" prefix="efg-"/>
</ConfigProvider>);
assert(newWrapper.find('.abcd-icon > svg'));
assert(newWrapper.find('.abcd-icon > efg-icon-remote'));
});
});

0 comments on commit c70ae13

Please sign in to comment.