You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
66 lines
1.9 KiB
66 lines
1.9 KiB
4 years ago
|
import { SmileOutlined } from '@ant-design/icons';
|
||
|
import IconContext from '@ant-design/icons/lib/components/Context';
|
||
2 years ago
|
import React from 'react';
|
||
2 years ago
|
import { render } from '../../../tests/utils';
|
||
4 years ago
|
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 => {
|
||
2 years ago
|
style.parentNode?.removeChild(style);
|
||
4 years ago
|
});
|
||
|
});
|
||
|
|
||
3 years ago
|
describe('csp', () => {
|
||
|
it('raw', () => {
|
||
2 years ago
|
render(
|
||
3 years ago
|
<ConfigProvider csp={{ nonce: 'little' }}>
|
||
|
<SmileOutlined />
|
||
|
</ConfigProvider>,
|
||
|
);
|
||
|
const styleNode = document.querySelector('style');
|
||
2 years ago
|
expect(styleNode?.nonce).toEqual('little');
|
||
3 years ago
|
});
|
||
4 years ago
|
|
||
3 years ago
|
it('mix with iconPrefixCls', () => {
|
||
2 years ago
|
const { container } = render(
|
||
3 years ago
|
<ConfigProvider iconPrefixCls="bamboo" csp={{ nonce: 'light' }}>
|
||
|
<SmileOutlined />
|
||
|
</ConfigProvider>,
|
||
|
);
|
||
|
|
||
|
const styleNode = document.querySelector('style');
|
||
|
|
||
2 years ago
|
expect(container.querySelector('.bamboo-smile')).toBeTruthy();
|
||
|
expect(styleNode?.nonce).toEqual('light');
|
||
3 years ago
|
});
|
||
4 years ago
|
});
|
||
|
|
||
|
it('nest', () => {
|
||
|
const Checker = () => {
|
||
|
const { csp } = React.useContext(IconContext);
|
||
2 years ago
|
return <div id="csp">{csp?.nonce}</div>;
|
||
4 years ago
|
};
|
||
|
|
||
2 years ago
|
const { container } = render(
|
||
4 years ago
|
<ConfigProvider iconPrefixCls="bamboo" csp={{ nonce: 'light' }}>
|
||
|
<ConfigProvider>
|
||
|
<SmileOutlined />
|
||
|
<Checker />
|
||
|
</ConfigProvider>
|
||
|
</ConfigProvider>,
|
||
|
);
|
||
|
|
||
|
const styleNode = document.querySelector('style');
|
||
|
|
||
2 years ago
|
expect(container.querySelector('.bamboo-smile')).toBeTruthy();
|
||
|
expect(styleNode?.nonce).toEqual('light');
|
||
|
expect(container.querySelector('#csp')?.innerHTML).toEqual('light');
|
||
4 years ago
|
});
|
||
|
});
|