ant-design/components/theme/__tests__/token.test.tsx
二货机器人 66a3594e95
refactor: Provide top theme export and theme adjuster (#36302)
* chore: change theme mode

* refactor: export theme

* refactor: top of theme

* chore: map of token

* chore: fix lint

* chore: rename

* test: fix test case
2022-06-29 20:34:00 +08:00

50 lines
1.2 KiB
TypeScript

import { Theme } from '@ant-design/cssinjs';
import * as React from 'react';
import { render, renderHook } from '../../../tests/utils';
import ConfigProvider from '../../config-provider';
import theme from '../export';
const { useToken } = theme;
describe('Theme', () => {
it('useTheme', () => {
const result = renderHook(() => useToken());
expect(result.current.theme instanceof Theme).toBeTruthy();
expect(result.current.hashId).toBeFalsy();
expect(result.current.token).toEqual(
expect.objectContaining({
colorPrimary: '#1890ff',
}),
);
});
it('ConfigProvider with seed', () => {
const Demo = React.forwardRef((_, ref: any) => {
const themeObj = useToken();
ref.current = themeObj;
return null;
});
const themeRef = React.createRef<ReturnType<typeof useToken>>();
render(
<ConfigProvider
theme={{
token: {
colorPrimary: 'red',
},
}}
>
<Demo ref={themeRef} />
</ConfigProvider>,
);
expect(themeRef.current!.token).toEqual(
expect.objectContaining({
colorPrimary: 'red',
colorPrimaryHover: '#ff3029', // It's safe to modify if theme logic changed
}),
);
});
});