mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-15 17:31:25 +08:00
0d67bde239
* feat: add useConfig hook to ConfigProvider * docs: format config-provide markdown * doc: add available version * test: add useConfig test * docs: add debug * chore: fix lint error * fix: getter dead loop * test: promote useConfig test coverage * docs(ConfigProvider): update available version
64 lines
1.4 KiB
TypeScript
64 lines
1.4 KiB
TypeScript
import React from 'react';
|
|
import ConfigProvider from '..';
|
|
import Form from '../../form';
|
|
import { render } from '../../../tests/utils';
|
|
import { resetWarned } from '../../_util/warning';
|
|
|
|
describe('ConfigProvider.useConfig', () => {
|
|
it('useConfig - componentSize', () => {
|
|
let size;
|
|
|
|
const App: React.FC = () => {
|
|
const { componentSize } = ConfigProvider.useConfig();
|
|
size = componentSize;
|
|
|
|
return null;
|
|
};
|
|
|
|
render(
|
|
<ConfigProvider componentSize='small'>
|
|
<App />
|
|
</ConfigProvider>,
|
|
);
|
|
|
|
expect(size).toBe('small');
|
|
});
|
|
|
|
it('useConfig - componentDisabled', () => {
|
|
let disabled;
|
|
const App: React.FC = () => {
|
|
const { componentDisabled } = ConfigProvider.useConfig();
|
|
disabled = componentDisabled;
|
|
return null;
|
|
};
|
|
|
|
render(
|
|
<Form disabled>
|
|
<App />
|
|
</Form>,
|
|
);
|
|
|
|
expect(disabled).toBe(true);
|
|
});
|
|
|
|
it('deprecated SizeContext', () => {
|
|
resetWarned();
|
|
|
|
const App: React.FC = () => {
|
|
const { SizeContext } = ConfigProvider;
|
|
const ctx = React.useContext(SizeContext);
|
|
|
|
return <div>{ctx}</div>;
|
|
};
|
|
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
render(<App />);
|
|
|
|
expect(errSpy).toHaveBeenCalledWith(
|
|
'Warning: [antd: ConfigProvider] ConfigProvider.SizeContext is deprecated. Please use `ConfigProvider.useConfig().componentSize` instead.',
|
|
);
|
|
errSpy.mockRestore();
|
|
});
|
|
});
|