Skip to content

Commit

Permalink
✅ test: 添加嵌套ThemeProvider 的测试用例
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx committed Jan 15, 2023
1 parent f494e0e commit 7066c3d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/containers/ThemeProvider/ThemeSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const ThemeSwitcher: FC<ThemeSwitcherProps> = memo(
else setAppearance(themeMode);
}, [themeMode]);

// 自动监听系统主题变更
useLayoutEffect(() => {
if (!darkThemeMatch) {
darkThemeMatch = matchThemeMode('dark');
Expand Down
13 changes: 13 additions & 0 deletions tests/hooks/useTheme.test.ts → tests/hooks/useTheme.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { renderHook } from '@testing-library/react';

import { ThemeProvider, useTheme } from 'antd-style';
import { FC, PropsWithChildren } from 'react';

describe('useTheme', () => {
it('如果没有 Provider,theme 对象时是 antd Token 默认值', () => {
Expand All @@ -15,6 +16,18 @@ describe('useTheme', () => {
expect(result.current.stylish).toEqual({});
});

it('嵌套 Provider 后能拿到准确的值', () => {
const Wrapper: FC<PropsWithChildren> = ({ children }) => {
return (
<ThemeProvider themeMode={'dark'}>
<ThemeProvider prefixCls={'kitchen'}>{children}</ThemeProvider>
</ThemeProvider>
);
};
const { result } = renderHook(useTheme, { wrapper: Wrapper });
expect(result.current.colorPrimary.toLowerCase()).toEqual('#1668dc');
});

it('自定义 Token', () => {});
it('自定义 Stylish', () => {});
});
2 changes: 0 additions & 2 deletions tests/hooks/useToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ describe('useAntdToken', () => {
const { result } = renderHook(useAntdToken);
expect(result.current.colorPrimary.toLowerCase()).toEqual('#1677ff');
});

it('TODO: 嵌套 CP 时能拿到准确的 token 值', () => {});
});

0 comments on commit 7066c3d

Please sign in to comment.