mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 17:59:57 +08:00
db0344c85f
* test: migrate part of ConfigProvider tests * test: migrate part of ConfigProvider tests * test: update snap * test: update snap * test: migrate part of ConfigProvider tests * fix: commented error case * chore: update snapshot name * test: csp test case * test: revert test case * test: Update snapshot * test: Update ser logic * test: more cov * test: cascader snapshit * test: update match * test: more detact * test: more handler * chore: Update snapshot * test: Table test case Co-authored-by: 二货机器人 <smith3816@gmail.com>
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { SmileOutlined } from '@ant-design/icons';
|
|
import IconContext from '@ant-design/icons/lib/components/Context';
|
|
import React from 'react';
|
|
import { render } from '../../../tests/utils';
|
|
import ConfigProvider from '..';
|
|
|
|
describe('ConfigProvider.Icon', () => {
|
|
beforeEach(() => {
|
|
// eslint-disable-next-line jest/no-standalone-expect
|
|
expect(document.querySelectorAll('style')).toHaveLength(0);
|
|
});
|
|
|
|
afterEach(() => {
|
|
document.querySelectorAll('style').forEach(style => {
|
|
style.parentNode?.removeChild(style);
|
|
});
|
|
});
|
|
|
|
describe('csp', () => {
|
|
it('raw', () => {
|
|
render(
|
|
<ConfigProvider csp={{ nonce: 'little' }}>
|
|
<SmileOutlined />
|
|
</ConfigProvider>,
|
|
);
|
|
const styleNode = document.querySelector('style');
|
|
expect(styleNode?.nonce).toEqual('little');
|
|
});
|
|
|
|
it('mix with iconPrefixCls', () => {
|
|
const { container } = render(
|
|
<ConfigProvider iconPrefixCls="bamboo" csp={{ nonce: 'light' }}>
|
|
<SmileOutlined />
|
|
</ConfigProvider>,
|
|
);
|
|
|
|
const styleNode = document.querySelector('style');
|
|
|
|
expect(container.querySelector('.bamboo-smile')).toBeTruthy();
|
|
expect(styleNode?.nonce).toEqual('light');
|
|
});
|
|
});
|
|
|
|
it('nest', () => {
|
|
const Checker = () => {
|
|
const { csp } = React.useContext(IconContext);
|
|
return <div id="csp">{csp?.nonce}</div>;
|
|
};
|
|
|
|
const { container } = render(
|
|
<ConfigProvider iconPrefixCls="bamboo" csp={{ nonce: 'light' }}>
|
|
<ConfigProvider>
|
|
<SmileOutlined />
|
|
<Checker />
|
|
</ConfigProvider>
|
|
</ConfigProvider>,
|
|
);
|
|
|
|
const styleNode = document.querySelector('style');
|
|
|
|
expect(container.querySelector('.bamboo-smile')).toBeTruthy();
|
|
expect(styleNode?.nonce).toEqual('light');
|
|
expect(container.querySelector('#csp')?.innerHTML).toEqual('light');
|
|
});
|
|
});
|